我有一个包含一些HTML的字符串。实施例...
<tr id="problem_header">
<td width="50%">Unit 5, Lesson 2: Ordering Decimals</td>
<td width="50%">Notes</span></td>
</tr>
<tr id="border_row">
<td class="border_cell" id="border_cell">----</td>
<td class="border_cell" id="border_cell">----</td>
</tr>
<tr class="problem_display_row">
<td valign="middle" class="problem_display" id="problem_display">
Place the following numbers in order from least to greatest.
<br><br>
0.0032, 0.0016, 0.0097, 0.0075, 0.0049
</td>
<td valign="middle" class="notes_display" id="notes_display">
</td>
</tr>
<tr class="problem_display_work">
<td valign="middle" class="problem_display" id="problem_display">
<span class="emphasis">0.0016, 0.0032, 0.0049, 0.0075, 0.0097</span>
</td>
<td valign="middle" class="notes_display" id="notes_display">
Starting with the highest place value, compare each corresponding place value on each number. Highest number wins! If there's a tie, move on to the next place value and keep going until you have a winner.
</td>
使用javascript,我可以通过他们的ID取出一些<tr>
吗?比如,摆脱<tr id="problem_header">
例如,但留下另一个<tr>
&#39; s
答案 0 :(得分:0)
var element = document.getElementById("problem_header");
element.parentNode.removeChild(element);
答案 1 :(得分:0)
以字符串格式执行此操作会很困难(可能是正则表达式,但真的很难),但jquery可以处理这个......
var x = $(YOURSTRING)
//remove values from x with regular jquery calls
return x.html()
答案 2 :(得分:0)
因为HTML是字符串格式,我想最好先执行它,即显示所有tr
和id="problem_header"
,一旦加载tr,删除{{1} }}
您可以将ID删除为
id="problem_header"
确保在编写脚本以显示所有tr元素后执行上述脚本。