【问题标题】:How to make radio :selected work in Safari如何使收音机:选定在 Safari 中工作
【发布时间】:2014-07-02 11:01:52
【问题描述】:

这适用于 Chrome,但不适用于 Safari:

require(['jquery'], function($)
{
    // store the value of the previous selected radio control 
    // before the current one gets selected
    $(document).on('focus', 'input[type=radio]', function () {
        // search all radio input fields with the same name within the same form
        // and store the value of active one into the oldValue property
        $(this).data('oldValue', $(this.form[this.name]).filter(':checked').val());
    });
});

sn-p 的哪一部分导致了问题?我在这里的黑暗中踩踏......

【问题讨论】:

    标签: jquery html forms radio-button


    【解决方案1】:

    改变这一行:

    $(this).data('oldValue', $(this.form[this.name]).filter(':checked').val());
    

    到这里:

    $(this).data('oldValue', $(this).closest('form').find(':checked').val());
    

    除此之外,您可以将focus 事件更改为change

    $(document).on('change', 'input[type=radio]', function () {
    

    【讨论】:

    • 这并没有解决我的问题,但它让我注意到了一个更潜在的问题:我将 console.log 放入事件块中但没有得到它,所以看起来整个事件是当我在 safari 中使用焦点时没有触发,请看这个小提琴:jsfiddle.net/TXLmk
    • 小提琴就是这一行 在 safari 中不起作用
    • 当一个单选按钮被点击或被选中时,Internet Explorer 和 Firefox 触发焦点事件。在 WebKit 中,不会触发此事件。 bugs.webkit.org/show_bug.cgi?id=92029
    • @PhilS:Windows Vista 上的 Chrome 30 和 Saf 5.1.7 会触发该事件。甚至到了 Saf 不断触发它并且必须强制关闭浏览器的地步。
    猜你喜欢
    • 2017-07-22
    • 2013-04-26
    • 1970-01-01
    • 2011-05-23
    • 2019-08-24
    • 2011-06-04
    • 2020-04-18
    • 2017-03-23
    相关资源
    最近更新 更多