我试图将一列或单个tds限制为仅接受数字。
这有可能吗?我只找到一些输入内容。
<table class="table table-striped" id="notfallTable">
<tr>
<th value="name">Name</th>
<th>Nachname</th>
<th>Nummer</th>
<th>Abteilung</th>
<th id="thCheckbox"><button id="checkAll" class="btn btn-success">Check all</button>
</th>
</tr>
</table>
$.getJSON("NotfallSMS.json", function(data) {
var items = [];
var checkbox = "test";
$.each(data, function(key, val) {
items.push("<tr>");
items.push("<td contenteditable>" + val.Name + "</td>");
items.push("<td contenteditable>" + val.Nachname + "</td>");
items.push("<td contenteditable>" + val.Nummer + "</td>");
items.push("<td contenteditable>" + val.Abteilung + "</td>")
items.push("<td class='check'><input class='check' type='checkbox'>" + "" + "</input></td>");
items.push("</tr>");
});
$("<tbody/>", {
html: items.join("")
}).appendTo("table");
});
答案 0 :(得分:0)
我对此有一个功能。
HTML
<input type="text" placeholder="number" onblur="OnlyNumber(event,false)" OnlyNumber="return SadeceRakam(event);">`
jQuery
function OnlyNumber(e, allowedchars) {
var key = e.charCode == undefined ? e.keyCode : e.charCode;
if ((/^[0-9]+$/.test(String.fromCharCode(key))) || key == 0 || isPassKey(key, allowedchars)) { return true; }
else { return false; }
}