请问大神哪里错了,为啥我的没反应
这哪里出错了,为啥我点按钮,没反应?
这哪里出错了,为啥我点按钮,没反应?
2016-11-22
没看出来你代码问题,可能符号有问题,下面是我的,你可以把你代码粘出来,我可以复制然后帮你检测哪错了
<body>
<div>
<input type="button" value="你好" id="btn" >
</div>
<script type="text/javascript">
var btn=document.getElementById("btn");
function you(){
alert("nihao");
}
var di={
jia:function(element,type,handler){
if (element.addEventListener) {
element.addEventListener(type,handler,false);
}else if(element.attachEvent){
element.attachEvent("on"+type,handler);
}else{
element["on"+type]=handler;
}
}
}
di.jia(btn,"click",you);
</script>
</body>
这样就对了
<script>标签改成———<script type="text/javascript">
div的闭合你没写
function前面星号去掉
]else if前面改成 }
script闭合也没写
var t= document.getElementById("w"); 写一次就行了
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>实践题 - 选项卡</title>
</head>
<body>
<div>
<input type="button" value="按钮" onClick="alert('hello')">
<input type="button" value="按钮1" onclick="show()">
<input type="button" value="按钮2" id="w">
</div>
<script type="text/javascript">
function show(){
alert("你妹的");
}
var t= document.getElementById("w");
var good={
blue:function(element,type,handler){
if(element.addEventListener){
element.addEventListener(type,handler,false);
}else if(element.attachEvent){
element.attachEvent("on"+type,handler);
}else{
element["on"+type]=handler;
}
}
}
good.blue(t,"click",show);
</script>
</body>
</html>
<body>
<div>
<input type="button" value="按钮" onClick="alert('hello')">
<input type="button" value="按钮1" onclick="show()">
<input type="button" value="按钮2" id="w">
<script>
*function show(){
alert("你妹的");
}
var t= document.getElementById("w");
var t= document.getElementById("w");
var good={
blue:function(element,type,handler){
if(element.addEventListener){
element.addEventListener(type,handler,false);
]else if(element.attachEvent){
element.attachEvent("on"+type,handler);
}else{
element["on"+type]=handler;
}
}
}
good.blue(t,"click",show);
举报