开发者

Javascript help, writing html elements

How do I write this HTML using javascript.

<div id="resizeControl">
    <input type="image" src="resuce.png" />
    开发者_运维知识库<input type="image" src="enlarge.png" />
</div>

and append it to a slidegallery object..

.net


var image1= document.createElement("input"); //create your input
image1.setAttribute('src','resuce.png'); //set the attributes
image1.setAttribute('type','image');

var image2= document.createElement("input");
image2.setAttribute('src','enlarge.png');
image2.setAttribute('type','image');

var resizeControl = document.createElement("div"); //create the parent div
resizeControl.id = "resizeControl"; //assign the id
resizeControl.appendChild(image1);  //append your images to the new div
resizeControl.appendChild(image2);

document.body.appendChild(resizeControl); //append the div to your body (or other element)

Code example on jsfiddle

More information on concepts used:

  1. Node.appendChild()
  2. document.createElement()
  3. element.setAttribute()


var div = document.createElement('div'),
input1 = document.createElement('input'),
input2 = document.createElement('input');

div.id = 'resizeControl';

input1.type = 'image';
input1.src = 'resuce.png';

input2.type = 'image';
input2.src = 'enlarge.png';

div.appendChild(input1);
div.appendChild(input2);

document.body.appendChild(div);


Javascript:

document.getElementById("Main").innerHTML += "<strong>Hello!</strong>";
document.getElementById("Main").innerHTML += "<div style='background:red'>Rrrrred!</div>";

HTML:

<div id="Main">
    Why... 
</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜