我有一个数字输入。当用户在其中写入数字时,背景应变为绿色。它适用于英文字符,但是当用户编写例如波斯数字时,什么也没有发生。我对表单提交进行了另一个验证,当数字字段中有非英文字符时,它还会检测到数字字段为空。
在 Windows 浏览器中,我无法将波斯数字粘贴到这些字段中。同样在 android 设备中,只有英文数字键盘出现,因此用户无法输入波斯字符。问题仅存在于iPhone用户中:他们可以编写波斯语,但在验证中字段看起来是空的。
$(document).ready(function(){
$(document).on("change input paste keyup",'.mandatory',function(e){
if ($(this).val()){
$(this).css({"background-color":"#b3d9b5"});
}
else{
$(this).css({"background-color":""});
}
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="number" class="mandatory">