۱۳۹۴/۰۹/۰۶, ۰۹:۴۴ ب.ظ
مشکل ام حل شد کد برای بقیه
کد پیاچپی:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function make(elem, content) {
var enode = document.createElement(elem); // li, p, div
var tnode = document.createTextNode(content); // content of the node
enode.appendChild(tnode); // write content in element
return enode;
}
function bake(insertNode, elem, content, attributes) {
var newElem = make(elem, content);
if (attributes !== false && typeof attributes !== 'undefined') {
for (prop in attributes) {
// prevent double IDs
if (prop === 'id' && document.getElementById(attributes[prop]) !== null)
continue;
newElem.setAttribute(prop,attributes[prop]);
}
}
document.getElementById(insertNode).appendChild(newElem);
}
function change(id, content) {
document.getElementById(id).textContent = content;
}
function changeHTML(id, content) {
document.getElementById(id).innerHTML = content;
}
</script>
</head>
<body >
<input type="button" onclick="bake('content', 'p', 'Hai im an paragraph!')" value="make p"/>
<input type="button" onclick="bake('content', 'div', 'Hai! im an div')" value="make div"/>
<input type="button" onclick="bake('content', 'p', 'Hai! im an right algined paragraph!', {align: 'right'})" value="make p right"/>
<input type="button" onclick="bake('content', 'p', 'Im a node with an ID', {id: 'myID'})" value="make #myID"/>
<input type="button" onclick="change('myID', 'Uh... i changed')" value="Change #myID"/>
<input type="button" onclick="changeHTML('myID', '<ul><li>Be aware that this list isnt touchable with JavaScript</li><li>when you do it that way</li></ul>')" value="ChangeHTML #myID"/>
<div id="content">
</div>
</body>
</html>