【问题标题】:Button renders as simple text when add programmatically inside table cell以编程方式在表格单元格内添加时,按钮呈现为简单文本
【发布时间】:2014-08-01 09:14:38
【问题描述】:

我正在尝试向表中动态添加行(最后一个 td 单元格包含按钮)

在 firefox 中,当我使用 firebug 查看生成的行时,我会喜欢

<td class="center_vertical">
    <a class="custom-button" data-name="63" name="drag_req" data-role="button"></a>
</td> 

但它不会呈现为按钮,就像简单的文本一样(不可点击,周围没有边框)。 我像

这样在 js 中创建行
        var rowContent = '<tr valign="middle"><td class="center_vertical"><a data-role="button" class="custom-button" name="drag_req" data-name="'+ responseData['id'] + '">Drag</a></td></tr>';
        $('#my_data_requests > tbody:last').html(rowContent);

( responseData 是包含所有使用键的字典) 当我在模板中创建相同的 html 时,它会呈现像按钮一样拖动而不是简单的文本。 有谁知道出了什么问题?

【问题讨论】:

  • 您使用的是哪个 jQM 版本?你在使用 table 小部件吗?

标签: javascript jquery html jquery-mobile


【解决方案1】:

可能是因为responseData['id'] 中的单引号?他们可能会弄乱字符串。我将单独声明 var,以便 rowContent 字符串中没有单引号。

var responseData_id = responseData['id'];
var rowContent = '<tr valign="middle"><td class="center_vertical"><a data-role="button" class="custom-button" name="drag_req" data-name="'+ responseData_id + '">Drag</a></td></tr>';
$('#my_data_requests > tbody:last').html(rowContent);

【讨论】:

  • 我已经改变了,但它仍然是一样的(我也尝试过 append 而不是 html 但一样)
猜你喜欢
  • 2020-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-16
  • 1970-01-01
  • 1970-01-01
  • 2016-01-08
相关资源
最近更新 更多