大佬教程收集整理的这篇文章主要介绍了将数据传递给jQuery click()函数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<span class="action removeAction">Remove</span>
然后,当点击该跨度时,我使用AJAX调用URl. AJAX事件需要知道该行的对象的ID?将该ID转换为点击功能的最佳方式是什么?
我以为我可以做这样的事情
<span class="action removeAction" id="1">Remove</span>
但是ID不应该从数字开始?对?然后我以为我可以做
<span class="action removeAction" id="my1">Remove</span>
然后,从ID中剥离“我的”部分,但这只是哟!
以下是我的点击事件和我的AJAX事件.
<script type="text/javascript" language="text/javascript"> $(document).ready(function() { $(".removeAction").click(function() { //AJAX here that needs to kNow the ID } }); </script>
注意:我不在寻找
$(this).attr("id");
我想通过一个以上的信息
谢谢.杰克.
$('.removeAction').click(function() { // Don’t do anything crazy like `$(this).attr('id')`. // You can get the `id` attribute value by simply accessing the property: this.id; // If you’re prefixing it with 'my' to validate as HTML 4.01,you can get just the ID like this: this.id.replace('my',''); });
顺便说一下,在HTML5,the id
attribute can start with a number or even be a number.
那么再说一次,如果你还在使用HTML5,那么你最好使用自定义数据属性,就像这样:
<span class="action removeAction" data-id="1">Remove</span>
以上是大佬教程为你收集整理的将数据传递给jQuery click()函数全部内容,希望文章能够帮你解决将数据传递给jQuery click()函数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。