2

html代码:

<div id="localPropList"></div>
<div id="assignedPropList"> </div>

js代码:

function    getLocalProposals()
        {  // filling these radio buttons dynamically 

            var htmlStringLocalPro = '<fieldset id="local_proposal_id_div" name ="radioGroup" data-role="controlgroup">';
            for (var k = 0; k < result.rows.length; k++) {
              var localProposal = result.rows.item(k);
            if( !(jQuery.inArray( localProposal.id, arrForQueuePropId ) >=0 ) )
        {var fieldId = 'localPro' + k;
            htmlStringLocalPro += '<input group="1" type="radio" name="local_proposal_id" id="' + fieldId + '" value="' + localProposal.enquiry_no + ',' + localProposal.id + '"/>'
                                          + '<label for="' + fieldId + '" data-iconpos="right">' + localProposal.enquiry_no+'-'+localProposal.caller_name+'</label>';
            }
     htmlStringLocalPro += '</fieldset>';
 }


   function  getAssignedproposals()
      {
     var htmlString = '<fieldset id="assigned_proposal_id_div"  name ="radioGroup" data-role="controlgroup">';
    for (var i = 0;i < obj.Proposal.length; i++) {
          proposalIds += obj.Proposal[i].id + ',';
      if( !(jQuery.inArray( obj.Proposal[i].id, arrForQueuePropId ) >=0 ) ){
                     var fieldId = 'ap' + i;
     htmlString += '<input group="1" type="radio" name="assigned_proposal_id" id="' + fieldId + '" value="' + obj.Proposal[i].enquiry_no + ',' + obj.Proposal[i].id + '"/><label for="' + fieldId + '" data-iconpos="right">' + obj.Proposal[i].enquiry_no + '-' + obj.Proposal[i].caller_name + '-' + obj.Proposal[i].post_code + '</label>';
                      //  htmlString += '<input type="radio" name="local_proposal_id" id="' + fieldId + '" value="' + obj.Proposal[i].enquiry_no + ',' + obj.Proposal[i].id + '"/><label for="' + fieldId + '" data-iconpos="right">' + obj.Proposal[i].enquiry_no + '-' + obj.Proposal[i].caller_name + '-' + obj.Proposal[i].post_code + '</label>';
                        }
                    }
    htmlString += '</fieldset>';}

     $("input:radio[name=local_proposal_id]:checked").each(function () {
       var prop = $(this).val().split(',');
 });
     $("input:radio[name=queue_proposal_id]:checked").each(function () {
           var prop = $(this).val().split(',');
});

如果选择了具有 name="assigned_proposal_id" 的单选按钮,我一次只需要选择一个单选按钮,那么它不应该允许选择 name="local_proposal_id]" 的任何单选按钮我不能分配不同的 id 我需要在名称的基础,我也不能为不同的组分配相同的名称,请告诉我解决方案是什么

4

6 回答 6

2

在 jQuery Mobile 中勾选/取消勾选,你需要使用.prop勾选或取消勾选,然后调用.checkboxradio('refresh').

演示

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

    // Uncheck radio buttons in #group1 and #group2
    $('#group1 [type=radio]:checked, #group2 [type=radio]:checked').prop('checked', false).checkboxradio('refresh');
    // "OR" to select all radio buttons in DOM
    $('[type=radio]:checked').prop('checked', false).checkboxradio('refresh');

    // Check clicked radio
    $(this).prop('checked', true).checkboxradio('refresh');
  });
});
于 2013-10-10T14:44:54.880 回答
0
     Disable Syntax:     
     $('input[name="name_here"]').attr('disabled', 'disabled');

 Don't go for the hardest thing 
Hussein Nazzal is correct but space matters    
between      input and '[' bracket 

if($('input[name="assigned_proposal_id"]:checked').val() != '')
{
$('input[name="local_proposal_id"]:radio').attr('disabled', 'disabled');
}

演示

于 2013-10-10T14:19:09.627 回答
0
$('input [name="assigned_proposal_id"]').click(function(){

if($('input [name="assigned_proposal_id"]').is(':checked')){ $('input [name="local_proposal_id"]').attr('disabled' , true) }

});

它会像侯赛因所说的那样工作

于 2013-10-10T13:33:03.953 回答
0

尝试以下

if($('input [name="assigned_proposal_id"]').is(':checked')){
    $('input [name="local_proposal_id"]').attr('disabled' , true)
}
于 2013-10-10T13:27:10.803 回答
0

这对我有用,考虑到根据选择器,此更改将应用​​于文档中具有相同类的所有 RadioButtons,在本例中为 class="chartIndex":

$(".chartIndex").change(function () {        
    $('[type=radio]:checked').prop('checked', false);
    $(this).prop('checked', 'checked');        
});

希望这可以帮助某人。问候。

于 2014-08-20T20:45:36.937 回答
0

这里是您的目的的 FIDDLE。它将取消选中所有单选按钮,然后选中我们单击的那个。

HTML:

<div id="localPropList">
<input name="assigned_proposal_id" type="radio" value="value1-1" />value1-1
<input name="assigned_proposal_id" type="radio" value="value1-2" />value1-2
<input name="assigned_proposal_id" type="radio" value="value1-3" />value1-3
</div>
<br/>
<div id="assignedPropList">
<input name="local_proposal_id" type="radio" value="value2-1" />value2-1
<input name="local_proposal_id" type="radio" value="value2-2" />value2-2
<input name="local_proposal_id" type="radio" value="value2-3" />value2-3
</div>
div selected : <span></span>

查询:

$('#localPropList input[name="assigned_proposal_id"], #assignedPropList input[name="local_proposal_id"]').change(function(){
    $('#localPropList input[name="assigned_proposal_id"], #assignedPropList input[name="local_proposal_id"]').prop('checked', false);
    $(this).prop('checked', true);
    $('span').html($(this).val());
});
于 2013-10-10T13:37:47.657 回答