如何获得onclick&“属性事件"返回“&财产事件"中的值? [英] How to get the onclick "attribute event" return value in "property event"?

查看:107
本文介绍了如何获得onclick&“属性事件"返回“&财产事件"中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下代码示例:

<a href="some url" onclick="confirm('ok to proceed ?')">bla</a>`

<script type="text/javascript">
    $(document).ready(function() {
              $("a").live("click", function (event) {
                    // In that function, I want to get 
                    // the "confirm" return value                  
               });
</script>

可以在不修改DOM的情况下获取此返回值??

It is possible to get this return value without modifying the DOM ??

谢谢.............

Thanks.............

推荐答案

否,该值未存储在任何地方供您访问.获得该值的唯一方法是将其移至jQuery处理的click事件,如下所示:

No, the value is not stored anywhere for you to access. The only way to get that value is to move it to a jQuery handled click event like this:

$(document).ready(function() {
    // The removeAttr removes the original "onclick" attribute
    $("a").removeAttr('onclick').live("click", function (event) {
       var ret = confirm('ok to proceed ?');
       // Do what you want here because `ret` has the return 
       // value from the `confirm` call.
    });
});

这篇关于如何获得onclick&amp;“属性事件"返回“&amp;财产事件"中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆