gpt4 book ai didi

javascript - 查询/JS : replace a row in a table

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:35:36 25 4
gpt4 key购买 nike

我正在尝试使用 JQuery 替换一整行,但似乎不起作用(该行未被替换)。这是示例代码的链接:http://jsfiddle.net/s2kwb/

JavaScript:

$("td.99999").first().parent().next().replaceWith("<tr><td >category 3</td>
<td >2222</td>
<td >something 22</td>
<td >something 22</td>
<td >$3,433</td>
<td >$300</td>
<td >$3,733</td>
<td >$349</td>
<td >$4,082</td>
</tr>");​

HTML:

<table border="1">
<tr >
<th>category</th>
<th>rank</th>
<th>priority</th>
<th>contact</th>
<th>price</th>
<th>tax</th>
<th>total price</th>
<th>shipping</th>
<th>Net payment</th>
</tr>
<tr class="displaytagOddRow">
<td class="99999">category 1</td>
<td class="99999">99999</td>
<td class="99999">something</td>
<td class="99999">something</td>
<td class="99999 alignRight">$3,433</td>
<td class="99999 alignRight">$300</td>
<td class="99999 alignRight">$3,733</td>
<td class="99999 alignRight">$349</td>
<td class="99999 alignRight">$4,082</td>
</tr>
<tr class="displaytagOddRow" style="Background-color:Red">
<td class="3333">category 2</td>
<td class="3333">3333</td>
<td class="3333">something</td>
<td class="3333">something</td>
<td class="3333 alignRight">$3,433</td>
<td class="3333 alignRight">$300</td>
<td class="3333 alignRight">$3,733</td>
<td class="3333 alignRight">$349</td>
<td class="3333 alignRight">$4,082</td>
</tr>
</table>

我做错了什么?

提前致谢。

最佳答案

终止每一行的字符串。另见 updated jsFiddle .

$("td.99999").first().parent().next().replaceWith("<tr><td >category 3</td>" +
"<td >2222</td>" +
"<td >something 22</td>" +
"<td >something 22</td>" +
"<td >$3,433</td>" +
"<td >$300</td>" +
"<td >$3,733</td>" +
"<td >$349</td>" +
"<td >$4,082</td>" +
"</tr>");​

Google JavaScript Style Guide推荐这种字符串连接并建议不要使用替代反斜杠换行符的多行字符串。

whitespace after the slash will result in tricky errors

关于javascript - 查询/JS : replace a row in a table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13957738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com