Jquery .click()函数对类问题的实现

时间:2013-02-23 08:00:46

标签: jquery html

我正在尝试在Jquery中实现一个简单的代码,如果我点击类的任何元素,我必须弹出一个说明你好

我试过了:

$(document).ready(function(){
    $(".thumb_radio").click(function(){

       alert("hello");


    });

});

但这不起作用。

HTML就像这样:

<tr>
<td>
<input id="thumb_radio_0" class="thumb_radio" type="radio" value="0" name="thumbnail_template">
Please select ...
</td>
</tr>
<tr>
<td>
<input id="thumb_radio_1" class="thumb_radio" type="radio" value="1" name="thumbnail_template">
one

</td>
<td>
<input id="thumb_radio_2" class="thumb_radio" type="radio" value="2" name="thumbnail_template">
two

</td>
<td>
<input id="thumb_radio_3" class="thumb_radio" type="radio" value="3" name="thumbnail_template">
three

</td>
<td>
<input id="thumb_radio_4" class="thumb_radio" type="radio" value="4" name="thumbnail_template">
four

</td>
</tr>

我错过了什么?

3 个答案:

答案 0 :(得分:1)

Prototype也会覆盖$变量。如果你想使用jQuery,你必须删除冲突。 jQuery有一个方法可以自己完成:$.noConflict

答案 1 :(得分:-1)

<script type="text/javascript" src="/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function(){
    $(".thumb_radio").click(function(){
       alert("hello");
    });
 });

</script>

提琴手示例:http://jsfiddle.net/UtcQu/

确切来源:view-source:http://fiddle.jshell.net/UtcQu/show/light/

如果您使用任何其他库以及本机jquery,可能需要执行jQuery.noConflict()之类的操作。

答案 2 :(得分:-1)

jQuery(function(){
    jQuery(".thumb_radio").click(function(){
       alert("hello");
    });

});