jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了调试jQuery选择器的返回值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_419_2@
我正在寻找一种方法来调试 jquery选择器返回的内容.我尝试过使用toString(),但只返回[object Object].

我实际上要做的是将回调附加到单选按钮.并且onclick
在其中一个按钮上,我想提交封闭表格.

因此我尝试做这样的事情:

$(".rating").stars({
    cancelShow: false,callback: function(ui,type,value,event) {
        $(this).closest('form').ajaxSubmit();
    }
});

不幸的是,没有任何事

这是我想要做的完整示例:

<script type="text/javascript" src="http://localhost:8000/media/js/jquery.js?v=1.4.2"></script>
<script type="text/javascript" src="http://localhost:8000/media/js/jquery.form.js?v=2.4.3"></script>
<script type="text/javascript" src="http://localhost:8000/media/js/jquery-ui.custom.min.js?v=1.8"></script>
<script type="text/javascript" language="javascript" src="http://localhost:8000/media/js/jquery.ui.stars.js?v=3.0.0b38"></script>
<link rel="stylesheet" type="text/css" media="all" href="http://localhost:8000/media/css/jquery.ui.stars.css?v=3.0.0b38" />        

<body>
 <script type="text/javascript">
    $(function() {
        $(".rating").children().not(":radio").hide();
        $(".rating").stars({
            cancelShow: false,event) {
                alert('NodeName: ' + this.nodeName);
                $(this).each(function() {
                    alert($(this).html());
                });

                alert($(this).length);
            }
        });
    });
 </script>

 <ul class="list">
  <li>
   <form class="rating" id="rating-1" action="/sniphunter/rate/1/" method="post">
    <input type="radio" name="score" value="1" id="rating-1-1" />
    <input type="radio" name="score" value="2" id="rating-1-2" />
    <input type="radio" name="score" value="3" id="rating-1-3" />
    <input type="radio" name="score" value="4" id="rating-1-4" />
    <input type="radio" name="score" value="5" id="rating-1-5" />
    <input type="submit" value="Rate"/>
   </form>
  </li>
 </ul>
</body>

解决方法

我下载了 Star Rating Widget(它看起来与你正在使用的相同)并进行了一些挖掘……星星插件完全删除了单选按钮并用div和链接替换它们.选择星形时,它会将值保存在表单内的隐藏输入中.

所以,在弄乱它之后,我发现你可以使用ui.$form来获取表单,所以试试这个:

$(function(){
    $(".rating").children().not(":radio").hide();
    $(".rating").stars({
        cancelShow: false,event)
        {
            alert( ui.$form.attr('id') );  // alerts the form ID
            ui.$form.ajaxSubmit();
        }
    });
});

编辑:哦,如果你想访问你的原始单选按钮,它们将被保存到ui.$rBoxs内部的ui对象中.以下代码段将提醒原始单选按钮的ID:

$(function(){
    $(".rating").children().not(":radio").hide();
    $(".rating").stars({
        cancelShow: false,event)
        {
            alert( ui.$rBoxs[(value-1)].id );
        }
    });
});
@H_419_2@

大佬总结

以上是大佬教程为你收集整理的调试jQuery选择器的返回值全部内容,希望文章能够帮你解决调试jQuery选择器的返回值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: