javascript - 无法更改 jQuery Mobile 中动态生成的按钮文本

标签 javascript jquery jquery-mobile cordova

我使用 jquery mobile 动态创建按钮,就像在我的 phonegap 应用程序中一样。

var table = document.getElementById("skiTable");
var row = document.getElementById("skiparticulars");
var clone = table.rows[1].cloneNode(true);

var skiFile = clone.cells[0].getElementsByTagName('input')[0];
var skiformTitle = clone.cells[0].getElementsByTagName('input')[1];

skiFile.id = "skifile" + skiRowCount;
skiFile.value = "";
skiformTitle.id = "formTitle" + skiRowCount;

skiformTitle.value = "";
row.appendChild(clone);
skiRowCount++;

html代码是这样的

<table>
 <tr>
   <td>
      <input type="hidden" id="skifile1" />
      <input type="button" id="formTitle1"/>
   </td>
 <tr>
</table>

这里是更改按钮值的代码:

$("#skifile" + k).val(results.rows.item(j).ski_file);

        $('#formTitle'+ k).val(results.rows.item(j).formTitle);
        $("#formTitle"+k).button("refresh");
tried this also 
//$("#formTitle" + k).prop('value',results.rows.item(j).formTitle).button("refresh");

但它永远不会改变值。

我引用了这个jquerymobile dynamically changing text for button issue

还有这个How to change the text of a button in jQuery?

最佳答案

jQuery Mobile 1.4 示例:

工作示例:http://jsfiddle.net/Gajotres/8x8HE/

JavaScript

$('#formTitle1').parent().html($('#formTitle1').parent().html() + 'Button text');

没有文本的按钮 HTML:

<div class="ui-btn ui-input-btn ui-corner-all ui-shadow">
    <input type="button" id="formTitle1">
</div>

带文本的按钮 HTML

<div class="ui-btn ui-input-btn ui-corner-all ui-shadow">
    <input type="button" id="formTitle1">Button text
</div>

阅读this如果您想了解如何自定义 jQuery Mobile 元素,请阅读这篇文章。

jQuery Mobile 1.3 及以下示例:

工作示例:http://jsfiddle.net/Gajotres/wLzA7/

JavaScript

$('#formTitle1').parent().find('span span').html('Button text');

没有文本的按钮 HTML:

<div data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c" data-disabled="false" class="ui-btn ui-shadow ui-btn-corner-all ui-btn-up-c" aria-disabled="false">
    <span class="ui-btn-inner">
        <span class="ui-btn-text"></span>
    </span>
    <input type="button" id="formTitle1" class="ui-btn-hidden" data-disabled="false"/>
</div>

带文本的按钮 HTML

<div data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c" data-disabled="false" class="ui-btn ui-shadow ui-btn-corner-all ui-btn-up-c" aria-disabled="false">
    <span class="ui-btn-inner">
        <span class="ui-btn-text">Button text</span>
    </span>
    <input type="button" id="formTitle1" class="ui-btn-hidden" data-disabled="false"/>
</div>

关于javascript - 无法更改 jQuery Mobile 中动态生成的按钮文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23733514/

相关文章:

php - Javascript 和 PHP 的这种数据有什么问题

javascript - Angular2 boot.ts 意外错误

javascript - 在 Karma/Jasmine 单元测试中注入(inject) Angular 的 $timeout 服务的实际实现

javascript - 如何使用javascript在表中动态添加输入

javascript - 获取特定点的 URL (jQuery/JavaScript)

javascript - JQuery 悬停和 SlideToggle

css - 如何使用 JAM slider /范围动态更改 .ui-slider-handle 背景图像

javascript - Jquery移动功能不起作用==页面刷新?

javascript - 如何在 typescript 中提供自动代码完成的同时将数组减少为对象?

android - 无法调用 determinedVisibility() - 从未看到 pid 的连接 - 无法导航到 Html 页面