简体   繁体   English

jQuery移动单选按钮

[英]jQuery mobile radio buttons

I am developing a web application with jQuery 1.9.1 and jQuery Mobile 1.3.2. 我正在使用jQuery 1.9.1和jQuery Mobile 1.3.2开发Web应用程序。

I have some problems with horizontal radio buttons. 我的水平单选按钮有一些问题。 They display an icon: data-icon="radio-on" . 它们显示一个图标: data-icon="radio-on"

带有数据图标收音机的单选按钮

The radio buttons are added dynamically to the DOM. 单选按钮将动态添加到DOM。

My HTML : 我的HTML:

<div id="id_card">
    <div id="custom_properties"><h2>DATA NOT INCLUDED IN ID CARD</h2></div>
    <div id="default_properties"><h2>ID CARD DATA</h2></div>
</div>

My Javascript: 我的Javascript:

var idCards = [....]; // Array of objects

// This variable contains the HTML corresponding to the custom ID CARDS.
var customIdCardHtml = '<ul data-role="listview" id="custom_idcard_list" data-inset="true">';
// This variable contains the HTML corresponding to the known ID CARDS.
var existingIdCardHtml = '<ul data-role="listview" id="idcard_list" data-inset="true">';

// This variable contains the concatenation of both 'customIdCardHtml' and 'existingIdCardHtml'.
var idCardHtml = '';

// Treat each ID CARD in the array
for(var i=0; i<idCards.length; i++) {
    // Get the current ID CARD
    var idCard = idCards[i];

    // Make sure it is not null, otherwise do nothing with it
    // and pass to the next one.
    if(idCard) {
        // Create an ID card line made of a label and a radio button
        var html = '<li class="idcard_property" data-role="fieldcontain">';

        html += '<fieldset data-role="controlgroup" data-type="horizontal">';
        html += '<legend>'+idCard.NAME+'</legend>';

        // Populate the radio button with values
        for(var j=0; j<idCard.VALUES.length; j++) {
            // Get the current value of the selected ID CARD
            var value = idCard.VALUES[j];
            if(idCard.VALUE == value) {
                html += '<input type="radio" class="select_idcard_property" name="'+idCard.TAG+'" id="'+idCard.TAG+'_'+value+'" value='+value+' checked="checked">';
                html += '<label for="'+idCard.TAG+'_'+value+'" data-icon="radio-off">'+value+'</label>';
            } else {
                html += '<input type="radio" class="select_idcard_property" name="'+idCard.TAG+'" id="'+idCard.TAG+'_'+value+'" value='+value+'>';
                html += '<label for="'+idCard.TAG+'_'+value+'">'+value+'</label>';
            }
        }
        html += '</fieldset>';
        html += '</li>';

        // Depending on the type of ID Card (custom or existing)
        // append the html to a list or another
        if(idCard.CUSTOM)
        {
            customIdCardHtml += html;
        } else {
            existingIdCardHtml += html;
        }
    }
}

customIdCardHtml+='</ul>';
existingIdCardHtml+='</ul>';

$('#custom_properties').append(customIdCardHtml);
$('#default_properties').append(existingIdCardHtml);

$('#id_card').trigger('create');

Here is the code jQM generates: 这是jQM生成的代码:

<div class="ui-radio" style="display: block;">
  <input type="radio" name="TEST" id="TEST_NO" value="NO" style="display: block;">
  <label for="TEST_NO" data-corners="true" data-shadow="false" data-iconshadow="true" data-wrapperels="span" data-icon="radio-on" data-theme="a" data-mini="false" class="ui-last-child ui-radio-on ui-btn-active ui-btn ui-btn-corner-all ui-fullsize ui-btn-icon-left ui-btn-up-a" style="display: block;">
    <span class="ui-btn-inner" style="display: block;">
      <span class="ui-btn-text" style="display: inline;">NO</span>
      <span class="ui-icon ui-icon-radio-on ui-icon-shadow" style="display: inline;">&nbsp;</span>
    </span>
  </label>
</div>

How to tell jQM not to display the span with class="ui-icon..." ? 如何告诉jQM不要使用class="ui-icon..."显示span

For the record, the icon is not shown at initialization. 为了记录,该图标在初始化时不显示。 It is only displayed when the radio button is clicked, the user goes to another tab and returns to the tab with radio buttons. 仅在单击单选按钮时显示,用户转到另一个选项卡并返回带有单选按钮的选项卡。

Thanks 谢谢

I finally used omar's solution $('span.ui-icon').remove(); 我终于使用了$('span.ui-icon').remove();的解决方案$('span.ui-icon').remove(); .

But it doesn't look right. 但这看起来并不正确。 This is just a work around. 这只是解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM