Ich habe versucht, ein dynamisches P-Element mit dem Rand-links als 33px zu erstellen.Aber es funktioniert nicht. Aber das gleiche funktioniert gut, wenn die linke nicht verwendet wird (Rand) und mit statischen HTML-p-Element. Wieso ist es so? Ich habe es mit dem IE11 und Chrome Version 60.0.3112.113 versucht.margin-left für DOM-Element funktioniert nicht
<!DOCTYPE html>
<html>
<head>
<title>Chat</title>
<meta charset="utf-8">
</head>
<body>
<div id="screenv" style="border:1px solid black;margin: 5px;padding: 5px;width: 300px;height: 300px;"></div></br>
<input id="tb" type="text" style="border:1px solid black;margin: 5px;padding: 5px;width: 300px;" placeholder="Enter your text"></input>
<button onclick="submit()">Submit</button>
<p style="margin-left:33px;">hello</p>//css works fine
<script type="text/javascript">
var you="",screen="",msg="",c_time="",val="",d,h,m,line;
function submit() {
val=document.getElementById("tb").value;
screen=document.getElementById('screenv');
you=document.createElement("div");
you.innerHTML="You:";
screen.appendChild(you);
c_time=document.createElement("p");
d = new Date();
h = d.getHours();
m = d.getMinutes();
c_time.innerHTML = h+":"+m;
c_time.style.display="inline";
c_time.style.color="grey";
msg=document.createElement("p");
msg.innerHTML=val;
msg.style.margin-left="33px";//not working
line=document.createElement("br");
you.appendChild(c_time);
you.appendChild(line);
you.appendChild(msg);
document.getElementById("tb").value="";
}
</script>
</body>
</html>
Ändern Sie 'margin-left' in' marginLeft'. – Phil
_ "Warum ist das so?" _ - weil jeder, der sich mit den Grundlagen der Syntax beschäftigt hat, weiß, '-' ist der Subtraktionsoperator ... – CBroe