이 appendChild() method.but의 예제에서 작업하고 있습니다. 차이점은 여기에 있습니다. div에 동적으로 텍스트를 추가하려고합니다. 괜찮습니다. 그러나 어려운 부분은 텍스트입니다. 나는 color.How에 빨간색으로 추가 할 싶습니다. 은 내가동적으로 추가 된 텍스트에 색상을 추가하십시오.
text.setAttributes('color',"red");
을 시도하지만이 아니야! 전혀 그렇지 않았다,이 작업을 도와주세요 ?? 수행 할 수있는 방법, 감사 !!!! 즉 당신의 DIV에 모든 것이 있다면
전체 코드가 ............
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function create_text(){
var mydiv = document.getElementById("mydiv");
var text = document.createTextNode(" New text to add.");
mydiv.appendChild(text);
}
</script>
</head>
<body>
<button onclick="create_text();">Create Text Node</button>
<div id="mydiv">Welcome, here is some text.</div>
</body>
</html>
, 당신은 요소에 속성으로 스타일을 설정하지 : 다음도 가능하다. 그들은 요소의'style' 객체로 가야합니다. –