課程
/前端開發(fā)
/JavaScript
/DOM事件探秘
這哪里出錯(cuò)了,為啥我點(diǎn)按鈕,沒反應(yīng)?
2016-11-22
源自:DOM事件探秘 2-4
正在回答
沒看出來你代碼問題,可能符號(hào)有問題,下面是我的,你可以把你代碼粘出來,我可以復(fù)制然后幫你檢測哪錯(cuò)了
<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>
這樣就對(duì)了?
<script>標(biāo)簽改成———<script type="text/javascript">
div的閉合你沒寫
function前面星號(hào)去掉
]else if前面改成 }
script閉合也沒寫
var t= document.getElementById("w"); 寫一次就行了
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>實(shí)踐題 - 選項(xiàng)卡</title>
</head>
<input type="button" value="按鈕" onClick="alert('hello')">
<input type="button" value="按鈕1" onclick="show()">
<input type="button" value="按鈕2" id="w">
function show(){
alert("你妹的");
var t= document.getElementById("w");
var good={
blue:function(element,type,handler){
if(element.addEventListener){
good.blue(t,"click",show);
</html>
]else if(element.attachEvent){ ? 第一個(gè)符號(hào)錯(cuò)了應(yīng)該是
<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);
第一行是show換成handler試下
舉報(bào)
DOM事件?本課程會(huì)通過實(shí)例來給小伙伴們講解如何使用這些事件
5 回答請(qǐng)問一下,我的代碼哪里出錯(cuò)了,為什么點(diǎn)擊按鈕沒有反應(yīng)呢?
2 回答大神,幫我看看這段代碼哪里錯(cuò)了
1 回答這串代碼哪里錯(cuò)了,為什么點(diǎn)登陸沒有反應(yīng)
3 回答我在谷歌瀏覽器上測試沒反應(yīng)啥情況啊,誰給看看我哪里錯(cuò)了嗎?
2 回答麻煩看下錯(cuò)在哪里了,不知道哪里出錯(cuò),點(diǎn)擊沒反應(yīng)
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-11-22
沒看出來你代碼問題,可能符號(hào)有問題,下面是我的,你可以把你代碼粘出來,我可以復(fù)制然后幫你檢測哪錯(cuò)了
<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>
2016-11-22
這樣就對(duì)了?
<script>標(biāo)簽改成———<script type="text/javascript">
div的閉合你沒寫
function前面星號(hào)去掉
]else if前面改成 }
script閉合也沒寫
var t= document.getElementById("w"); 寫一次就行了
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>實(shí)踐題 - 選項(xiàng)卡</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>
2016-11-22
]else if(element.attachEvent){ ? 第一個(gè)符號(hào)錯(cuò)了應(yīng)該是
}else if(element.attachEvent){
2016-11-22
<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);
2016-11-22
第一行是show換成handler試下