你好,我有這個結構,許多行:jQuery的文本()返回不需要的字符
<div class="row">
<div class="input-group col-lg-1" >
<span class="input-group-addon">
<input type="checkbox">
</span>
<span id="value">
@Html.DisplayFor(modelitem => item.DeviceInstanceId)
</span>
</div>
*
*
*
</div>
其中@Html.DisplayFor(modelitem => item.DeviceInstanceId)
是一個數字。
我得到與選中的複選框連接的跨度的值。 有了這個代碼:
$(document).ready(function() {
$("#reservations").click(function() {
var Ids = new Array();
$(".table input:checked").each(function() {
Ids.push(($(this).parentsUntil("row").children("#value").text()));
})
console.log(Ids);
});
});
而IDS是這樣的:
["↵ 38↵ ", "↵ 40↵ ", "↵ 41↵ "]
我應該如何提高我的JS代碼擺脫那些進入和空格?
查找功能(「#值」),而不是兒童(「#值」) –
@NavinRauniyar:爲什麼? –
查找和孩子沒有區別。仍然不想要的字符 – szpic