2011-04-28 110 views
2


我试图在单击图像时提醒某些文本。.click()对图像无法正常工作

javascript代码:

$(document).ready(function() { 
    $(".delRow").click('function() { 
     alert("hello!"); 
    }); 
}); 

的html代码:

<img src="../images/delete.png" alt="delete" class="delRow"></img> 

此代码似乎直截了当;但是,它没有按预期工作。使用.click时图像的处理方式是否有所不同?

-Thanks,
丰富

+1

那是''''之前函数(){'的问题,一个错字或者是在你的代码? – icktoofay 2011-04-28 02:56:16

+1

它在做什么/不做什么?我注意到''.click('function()...'中有一个打开的引号,这是你的文章中的错字,还是在你的代码中? – 2011-04-28 02:58:17

+0

这是一个错字,我将代码改为: \t $( “delRow。 ”)点击(函数(){ \t警报(“ 你好!”); \t}); 但是,它仍然无法按预期工作,我与他们班多张图片。但我不认为这会导致问题 – dottedquad 2011-04-28 03:08:10

回答

3
$(document).ready(function() { 
    $(".delRow").click(function() { 
     alert("hello!"); 
    }); 
}); 

WORKING DEMO

+0

该代码按照预期的方式工作。我的形象仍然存在问题。 – dottedquad 2011-04-28 03:12:44

+0

在导致此问题的.click之前有代码:-) – dottedquad 2011-04-28 03:37:03

+0

很高兴您找到答案@dottedquad请将您的解决方案发布并接受为答案或接受此处给出的答案之一 – mcgrailm 2011-04-28 14:37:25

2

你有多余'的点击。(函数(){

应该

$(document).ready(function() { 
    $(".delRow").click(function() { 
     alert("hello!"); 
    }); 
}); 
+0

Arg!我总是这样做! – dottedquad 2011-04-28 03:04:38

1
$(document).ready(function() { 
    $(".delRow").click(function() { 
     alert("hello!"); 
    }); 
}); 

删除 “'” 前秒function