简体   繁体   English

使用jasny inputmask清除输入字段?

[英]Clear input field using jasny inputmask?

I use jasny bootstrap with inputmask to validate input. 我使用jasny bootstrap和inputmask来验证输入。

http://jasny.github.io/bootstrap/ http://jasny.github.io/bootstrap/

Having the following code. 具有以下代码。

<input id="foo" type="text" class="form-control" data-mask="999-99-999-9999-9" placeholder="ISBN">

How can I clear the value of the input field? 如何清除输入字段的值? I have tried the following: 我尝试了以下方法:

$("#foo").val('');

It doesn't clear the value. 它不会清除值。 The previously entered value is still there. 先前输入的值仍然在那里。 It feels like the jasny inputmask object has some state, which I'm unsure how to reset. 感觉像jasny inputmask对象具有某种状态,我不确定该如何重置。

All u need to do is use html code 您需要做的就是使用html代码

<input id="foo" type="text" class="form-control" data-mask="999-99-999-9999-9" placeholder="ISBN">
<input type="button" id="clear" value="clear">

and the script 和脚本

<script type="text/javascript">
 $(document).ready(function() {
  $("#clear").click(function(){
   $("#foo").val("");
  });
 });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM