BTEC IT 第 20 单元 - 网站设计/JavaScript/提示框
外观
提示框(结构化代码)
<head>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var e = document.getElementById("go");
e.addEventListener( "click", function() {
var name=prompt("What is your name?","No name");
if ( name!=null && name!="" ) {
output = "Hello " + name;
}
else {
output = "Hey, I asked you your name!";
}
document.getElementById( "msg" ).innerText = output;
}, false);
});
</script>
<head>
<body>
<form name="myForm">
<input id="go" type="button" value="Click this button now">
</form>
<p id="msg"></p>
</body>