这适用于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());
});
});
该片段的哪一部分造成了麻烦?我在这里黑暗中踩到了......
答案 0 :(得分: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 () {