0

我正在尝试在 Jquery 中实现一个简单的代码,如果我单击类的任何元素,我必须得到一个弹出窗口说hello

我试过这个:

$(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>

我错过了什么?

4

3 回答 3

1

原型也覆盖了$变量。如果你想和它一起使用 jQuery,你必须消除冲突。jQuery 有一个自己的方法来做到这一点:$.noConflict

于 2013-02-23T08:15:31.617 回答
-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/

确切来源:查看来源: http: //fiddle.jshell.net/UtcQu/show/light/

jQuery.noConflict()如果您使用任何其他库以及本机 jquery,您可能需要做一些事情。

于 2013-02-23T08:58:58.983 回答
-1

尝试

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

});
于 2013-02-23T09:34:42.697 回答