close
function createButton(context, func){var button = document.createElement("input");
button.type ="button";
button.value ="im a button";
button.onclick = func;
context.appendChild(button);}
window.onload =function(){
createButton(document.body,function(){
highlight(this.parentNode.childNodes[1]);// Example of different context, copied function etc// createButton(this.parentNode, this.onclick);});}
http://stackoverflow.com/questions/8650975/javascript-to-create-a-button-with-onclick
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to make a BUTTON element with text.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
for(var i=0;i<10;i++)
{
var button = document.createElement('BUTTON');
button.id='btn'+i;
button.innerHTML = 'btn'+i;
button.onclick = function(){
setcookie(this.id);
//location.href='text_view.html';
};
document.body.appendChild(button);
}
}
function setcookie(file){
alert(file);
}
</script>
</body>
</html>
全站熱搜
留言列表