我被我的代码困住了。我需要代码在单击“UUENDA”按钮后删除输入文本行并发出警报,只允许数字。此外,如果该函数发现了一个空间,然后删除该空间,就好像它从未使用过一样。到目前为止,这就是我所处的位置:
功能:
function checkInp()
{
var x= historyId.value;
if (isNaN(x))
{
alert("only numbers are allowed");
return false;
}
}
输入:
<td id="history_cont" align="left" style="visibility:hidden">
Haigusjuhu kood:
<input type="text" name="doctor" id="historyId" onkeydown="checkInp()" onchange="" value="" class="txt_left" style="width:140px;" />
</td>
和按钮:
<td align="left" style="padding-left: 10px;">
<div><input id="updateButton" type="button" class='button' value="UUENDA" onclick="javascript:reloadDocumentList()" style="width:80px; height: 26px; font-size: 12px; font-weight:bold; cursor:ponter;" disabled="disabled" /></div>
<div style="margin:5px 0px 5px -5px;"><img src="images/progress.gif" alt="" border="0" id="progressIndicator" style="visibility:hidden" /></div>
</td>
最佳答案
我希望我理解正确:当单击按钮时,您需要检查输入字段中是否有除数字之外的字符。如果有,则删除输入字段的内容并发出警报。
您可能正在寻找这样的东西:
$('#updateButton').click(function() {
if (!$('#historyId').val().match(/^[0-9]*$/)) {
alert("Only numbers are allowed.");
$('#historyId').val('');
}
});
这是一个JSFiddle尝试一下。
关于javascript - 输入字符 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25562916/