社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Jquery

当数字输入字段中有点或逗号时,jQuery val()返回空字符串

Toskan • 6 年前 • 2278 次点击  

我 认为 这取决于你的操作系统中有多少设置。但是:对我来说,我可以输入点 . 输入字段。对于我的申请,这是不希望的。我想禁用小数,所有不是数字的东西

另外,jquery不检测数字字段中的点

https://codepen.io/jossnaz/pen/dLMmoQ

看起来像这样:

enter image description here

HTML格式:

Please type into the first input box some dots . then click out of the input box to trigger the change event <br> <br>
<input type="number" name="firstInput" value="....">
<input type="number" name="second" value="5">

<pre class="result"></pre>

Javascript代码:

$('input').on('change', function(){

  $('.result').html(
  'First input val: ' + $('input').first().val() + "<br/>" + "Second input val: "
  +   $('input').last().val()
);
})
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52702
文章 [ 2 ]  |  最新文章 6 年前