我有一个表(它是用 PHP 创建的(来自 mySQL 的数据)),看起来像这样:
<table class="data-table">
<tbody>
<tr>
<td class="databasecontent">maybe some values</td>
<td class="databasecontent">maybe empty</td>
</tr>
<tr>
<td class="databasecontent">another row</td>
<td class="databasecontent"></td>
</tr>
</tbody>
</table>
然后我得到一个列表,我希望将内容附加到:
<ul class="plannerlist" id="plannerlist2">
</ul>
(我总共得到了 6 个 <ul>
和 id="plannerlist1, 2, ..."
)。
所以我想要来自 .databasecontent:nth-child(1)
的文本附加到 ul#plannerlist1
用这个 JS:
var database1 = $("td.databasecontent:nth-child(1)").text;
$("ul#plannerlist1:visible").append('<input type="text" readonly value="' + database1 + '">');
var database2 = $("td.databasecontent:nth-child(2)").text;
$("ul#plannerlist2:visible").append('<input type="text" readonly value="' + database2 + '">');
and so on...
我认为 jQuery 应该可以工作,但它只是给我一个输入值:
function (a){return S(this,function(a){return void 0===a?r.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=a)})},null,a,arguments.length)}
我的代码有什么问题?
最佳答案
你应该使用 .text()
而不是 .text
如果你没有做错的话它会完美地工作。
关于javascript - 附加值为 ="' + 变量 + '"的 HTML 输入没有给我正确的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42487857/