我有一個註冊表格在html中,我想輸入電話號碼在textbox
和非數字字符將不會顯示,而單擊非數字鍵時。在這裏,我正在使用jQuery來達到這個目的,但是我無法得到正確的結果。jquery函數不工作在codeigniter
<div class="form-group col-sm-3">
<label>Mobile No<sup style="color:#ff0000;font-size:16px;">*</sup></label>
<input name="mobileno" type="text" id="mobileno" class="form-control" maxlength="10">
</div>
在這個網站已指定id屬性爲mobileno
和我的jQuery是
< script type = "text/javascript" >
$(document).ready(function() {
$('#mobileno').keydown(function(e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
} else {
var key = e.keyCode;
var ret = ((key == 8) || (key == 9) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))
if (!ret) {
e.preventDefault();
}
$(".error").css("display", ret ? "none" : "inline");
}
});
$("#mobileno").bind("paste", function(e) {
return false;
});
$("#mobileno").bind("drop", function(e) {
return false;
});
});
< /script>
但不能執行此功能...請幫我找一個solution..Thanks所有提前
你VAR RET =後'錯過了分號在JavaScript(。 ..(key> = 96 && key <= 105))'line。 – Alexander
@ Alexander-謝謝......但我不能執行jquery函數keydown() – Aswathy
這行已經放在'keydown()'處理程序中。有可能造成麻煩。 – Alexander