Javascript帮助,编写html元素

1 javascript

如何使用javascript编写此HTML.

<div id="resizeControl">
    <input type="image" src="resuce.png" />
    <input type="image" src="enlarge.png" />
</div>
Run Code Online (Sandbox Code Playgroud)

并将其附加到slidegallery对象..

.净

Mar*_*man 5

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)
Run Code Online (Sandbox Code Playgroud)

关于jsfiddle的代码示例

有关使用概念的更多信息:

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