单击jQuery mobile中的radiobutton时取消选中它

单击jQuery mobile中的radiobutton时取消选中它,jquery,jquery-mobile,radio-button,Jquery,Jquery Mobile,Radio Button,我试图使单选按钮不可勾选,当一个选中的单选按钮被点击,但我不明白。使用jQuery 1.9.1和jQuery Mobile 1.3.1。已经尝试了以前版本中的一些示例,但都不起作用 以下内容在JSFIDLE中可用,但在我尝试在浏览器中使用时不起作用 JS: HTML: 1. 2. 3. 4. 5. 6. 15 30 45 编辑:Javascript可以工作!必须为不同的单选按钮组添加两次(基于名称) 提示必须将代码添加到 $(document).delegate('.ui-page',pa

我试图使单选按钮不可勾选,当一个选中的单选按钮被点击,但我不明白。使用jQuery 1.9.1和jQuery Mobile 1.3.1。已经尝试了以前版本中的一些示例,但都不起作用

以下内容在JSFIDLE中可用,但在我尝试在浏览器中使用时不起作用

JS:

HTML:


1.
2.
3.
4.
5.
6.
15
30
45
编辑:Javascript可以工作!必须为不同的单选按钮组添加两次(基于名称)

提示必须将代码添加到 $(document).delegate('.ui-page',pageshow',function(){code-hier}); 而不是 $(文档)。准备好了。
原因说明如下

这里是如何取消选中
已选中单选按钮

创建所有单选按钮的数组

var radios = [];

$('[type=radio]').each(function () {
 var id = $(this).attr('id');
 var value = $(this).attr('value');
 var status = $(this).is(':checked');
 radios.push({
  'id': id,
   'value': value,
    'status': status
 });
});
这里的核心代码

$('[type=radio]').on('click', function () {
 var clicked = $(this);
 var id = $(this).attr('id');
 var status = $(this).is(':checked');
 var result = $.grep(radios, function (e) {
    return e.id == id;
 });
 var oldstatus = result[0].status;
 if (!oldstatus) {
  clicked.prop('checked', true).checkboxradio('refresh');
 } else {
  clicked.prop('checked', false).checkboxradio('refresh');
 }
 // Re-fill array to update changes..
 radios = [];
 $('[type=radio]').each(function () {
  var id = $(this).attr('id');
  var value = $(this).attr('value');
  var status = $(this).is(':checked');
  radios.push({
   'id': id,
    'value': value,
     'status': status
  });
 });
});

'check'
之后添加
.checkboxradio('refresh')这也没用。你有两组按钮,你想禁用其他组还是同一组?我不想禁用其中任何一个。我想有可能取消选中任何选中的单选按钮。是的,我知道了。如果对象为空,则第一个
有问题。所以你必须读取所有的按钮并将它们添加到一个数组中,然后读取数组。这和我的js一样。它可以在JSFIDLE中使用,但不能在浏览器中使用。试试这个
$(文档)。在('click','[type=radio]'上,函数(){
@grekandco正在使用哪个浏览器?我刚刚在iPhone4 Safari上对它进行了现场测试(不是小提琴)。它没有问题。这是我的错!非常感谢!@grekandco很棒,很高兴我能提供帮助:)
var radios = [];

$('[type=radio]').each(function () {
 var id = $(this).attr('id');
 var value = $(this).attr('value');
 var status = $(this).is(':checked');
 radios.push({
  'id': id,
   'value': value,
    'status': status
 });
});
$('[type=radio]').on('click', function () {
 var clicked = $(this);
 var id = $(this).attr('id');
 var status = $(this).is(':checked');
 var result = $.grep(radios, function (e) {
    return e.id == id;
 });
 var oldstatus = result[0].status;
 if (!oldstatus) {
  clicked.prop('checked', true).checkboxradio('refresh');
 } else {
  clicked.prop('checked', false).checkboxradio('refresh');
 }
 // Re-fill array to update changes..
 radios = [];
 $('[type=radio]').each(function () {
  var id = $(this).attr('id');
  var value = $(this).attr('value');
  var status = $(this).is(':checked');
  radios.push({
   'id': id,
    'value': value,
     'status': status
  });
 });
});