[英]How to add double forward slash in a string without commenting out in Javascript?
[英]How to add forward slash automatically in keyup function
我在某個字段中,當用戶在第二個字母后鍵入時,我需要自動添加正斜杠。 在jQuery中這可能嗎?
<input type="text" class="someclass"/>
$(document).on('keyup','.classname', function(){
var count = $(this).val();
if(count == 2)
{
// Need stuff here
}
});
您可以使用:
$(document).on('keyup','.someclass', function(){
var count = $(this).val().length;
if(count == 2 && e.keyCode != 8){
$(this).focus().val(function( index, value ) { return value + "/ " ; });
}
});
您可以這樣做:
$(document).on('keyup', '.someclass', function(e) { var count = $(this).val().length; if (count == 2) { $(this).val($(this).val() + "/"); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="someclass" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.