我有一個Javascript變量。變量如下給出如何使用Javascript刪除html標籤中的不需要的空格?
var str = '< table class = "buy_selection" >
<tbody>
<tr>
<th> size </th >
<td>
< select id = "Specification_select" name = "Specification" >
< option value = "014 black/white" > 014 black/white </option >
< option value = "100 white/v red" > 100/v red white </option >
< option value = "101 white/black" > 101 white/black </option >
< option value = "102 white/white" > 102/white </option >
</select >
</Td >
</tr >
<tr>
<th> color </th >
<td>
< select id = "Specification_select" name = "Specification" >
< option value = "23.0" > 23.0 </option >
< option value = "23.5" > 23.5 </option >
< option value = "24.0" > 24.0 </option > 24.5
< option value = "24.5" > </option >
< option value = "25.0" > 25.0 </option >
< option value = "25.5" > 25.5 </option >
< option value = "26.0" > 26.0 </option >
< option value = "26.5" > 26. 5 </option >
< option value = "27.0" > 27.0 </option >
< option value = "27.5" > 27.5 </option >
< option value = "28.0" > 28.0 </option >
< option value = "28.5" > 28.5 </option >
< option value = "29.0" > 29.0 </option >
< option value = "30.0" > 30.0 </option >
< option value = "30.5" > 30.5 </option >
< option value = "31.0" > 31.0 </option >
</select >
</td >
</tr > write <tr>
<th> reviews 10 0 Yen discount </th >
<td>
< select id = "Specification_select" name = "Specification" >,
< option value = "review to write" > write reviews </option >
< option value = "write a review [100-yen discount]" > [100-yen discount] write a review </option >
</select >
</td >
</tr >
</tbody > ';
我需要格式化這個表,並使用Javascript或jQuery分配到一個div。
我已經試過trim()
和html_entity_decode
,但沒有刪除任何不需要的空格。
< table class = "buy_selection" >
我該如何格式化變量。請指教。
如果數據按原樣提供給您,那麼您始終可以使用一個好的文本編輯器來清理它,而不是從代碼中清除它。 – techfoobar