2012-06-28 23 views
0

checkboxs顯示標籤文本我有一個JqMobile代碼: -在檢查中,JqMobile

http://jsfiddle.net/qgueS/

我想要做的事情是對選中複選框,顯示在上面的<h3>Select</h3>各自的標籤文本,例如,如果選擇Bajaj Pulsar和Honda Shine,然後像這樣顯示...

<h3>Bajaj Pulsar, Honda Shine,...</h3> 

任何人都可以幫忙嗎?

回答

1

首先,將id添加到div

<div data-role="collapsible" data-content-theme="c" data-iconpos="right" id="foo"> 

接着,負載JS這樣的:

$(document).ready(function(){ 
    var h3_old = $('#foo h3 .ui-btn-text').text(); 
    $('#foo input').change(function(){ 
     var h3_new = new Array(); 
     $('#foo input:checked').each(function(){ 
      h3_new.push($(this).parent('div').find('.ui-btn-text').text()); 
     }); 
     if (h3_new.length > 0){ 
      $('#foo h3 .ui-btn-text').text(h3_new.join(', ')); 
     } else { 
      $('#foo h3 .ui-btn-text').text(h3_old); 
     } 
    }); 
});​