我正在研究 asp.net mvc 网站,我有 4 个下拉菜单和 4 个这样的文本框
dialprefix1 callfromnumber1
dialprefix2 callfromnumber2
dialprefix3 callfromnumber3
dialprefix4 callfromnumber4
我想要如果 dialprefix1 下拉列表的值为 44 那么 callfromnumber1 应该
有数字值 - done 应该以 0 0r 1,2,7,8 开头,否则显示警报(不工作)如果数字以 0 开头,那么 callfromnumber1 中允许的长度是 10(工作)如果数字以 1,2,7 开头, 8 那么 callfromnumber1 中允许的长度是 9 (工作)
我已经这样编码了:
$(document).ready(function () {
$("#DefaultCallFrom1, #DefaultCallFrom2, #DefaultCallFrom3, #DefaultCallFrom4").keydown(function (event) {
// Allow: backspace, delete, tab, escape, and enter
if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
// Ensure that it is a number and stop the keypress
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
event.preventDefault();
}
}
});
if ($("#DefaultCallFrom1").val().match("5")) {
displayAlertMessage($("#DefaultCallFrom1").val().substring(0, 1) + "Number must start with 0, 1, 2, 7 or 8");
}
$("#DefaultCallFrom1").keypress(function () {
if ($("#Dialprefix1").val() == "44") {
if (this.value.substring(0, 1) == "0")
return this.value.length <= 10
else
return this.value.length <= 9
}
})
$("#DefaultCallFrom2").keypress(function () {
if ($("#Dialprefix2").val() == "44") {
if (this.value.substring(0, 1) == "0")
return this.value.length <= 10
else
return this.value.length <= 9
}
})
$("#DefaultCallFrom3").keypress(function () {
if ($("#Dialprefix3").val() == "44") {
if (this.value.substring(0, 1) == "0")
return this.value.length <= 10
else
return this.value.length <= 9
}
})
$("#DefaultCallFrom4").keypress(function () {
if ($("#Dialprefix4").val() == "44") {
if (this.value.substring(0, 1) == "0")
return this.value.length <= 10
else
return this.value.length <= 9
}
})
});
另外,我可以为所有四个制作一个按键事件吗(现在我在这个片段的末尾有四个按键。
[编辑]
<td style="padding-left: 1px">
<input type="text" value="1" readonly="readonly" name="srNo" id="srNo" disabled="disabled" class="tiny" style="text- align:right">
<select name="Dialprefix1" id="Dialprefix1">
<option value="44">+44</option>
<option value="001">+001</option>
<option value="11" selected="selected">+11</option>
<option value="12">+12</option>
<option value="13">+13</option>
</select>
<input type="text" value="" name="DefaultCallFrom1" id="DefaultCallFrom1" class="textarea normal" autocomplete="off">
<br>
<input type="text" value="2" readonly="readonly" name="srNo" id="srNo" disabled="disabled" class="tiny" style="text- align:right">
<select name="Dialprefix2" id="Dialprefix2">
<option value="44">+44</option>
<option value="001">+001</option>
<option value="11" selected="selected">+11</option>
<option value="12">+12</option>
<option value="13">+13</option>
</select>
<input type="text" value="" name="DefaultCallFrom2" id="DefaultCallFrom2" class="textarea normal" autocomplete="off">
<br>
<input type="text" value="3" readonly="readonly" name="srNo" id="srNo" disabled="disabled" class="tiny" style="text- align:right">
<select name="Dialprefix3" id="Dialprefix3">
<option value="44">+44</option>
<option value="001">+001</option>
<option value="11" selected="selected">+11</option>
<option value="12">+12</option>
<option value="13">+13</option>
</select>
<input type="text" value="" name="DefaultCallFrom3" id="DefaultCallFrom3" class="textarea normal" autocomplete="off">
<br>
<input type="text" value="4" readonly="readonly" name="srNo" id="srNo" disabled="disabled" class="tiny" style="text- align:right">
<select name="Dialprefix4" id="Dialprefix4">
<option value="44">+44</option>
<option value="001">+001</option>
<option value="11" selected="selected">+11</option>
<option value="12">+12</option>
<option value="13">+13</option>
</select>
<input type="text" value="" name="DefaultCallFrom4" id="DefaultCallFrom4" class="textarea normal" autocomplete="off">
</td>
请建议