4-7编程练习
来源:4-7 编程练习
慕圣2241928
2018-09-06 15:52:06
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>location对象</title>
</head>
<body>
<input type="button" value="打开页面" id="open">
</body>
<script type="text/javascript">
//补充代码
document.getElementsByTagName("input").onclick=function(){
var a= confirm("请选择");
if(a){
alert(location.href);
}
}
</script>
</html>
请问为什么没有弹出确认框?
1回答
一叶知秋519
2018-09-06
将js内的代码改为:
<script type="text/javascript"> //补充代码 document.getElementsByTagName("input")[0].onclick=function(){ var a= confirm("请选择"); if(a){ alert(location.href); } } </script>
document.getElementsByTagName("input")获取到的是集合,选取集合第一个元素才是input元素。
祝学习愉快!
相似问题