javascript - 输入字符 Controller

标签 javascript html function

我被我的代码困住了。我需要代码在单击“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/

相关文章:

javascript - 在 Javascript 中,为什么验证器在函数调用前请求 'new'?

javascript:使用 IF 语句而不是 OR 设置默认值

javascript - Node.js 文件观看基本示例

javascript - 如何通过超时和监听器创造 future

html - CSS 选择性问题

javascript - 在 JS 中存储函数的值

javascript - 在页面加载时运行 javascript 函数

html - CSS 外部文件从它自己的文件夹链接到我的 html 文件

javascript - 在 asp.net aspx 页面上使用 jquery 获取隐藏字段值时遇到问题

r - 如何为包装 ggplot() 的自定义函数编写可选参数?