function checkTextValid(control, length)
{
//检查文本内容长度
if(control.value.length >= length)
window.event.keyCode = 0;
//过滤特殊字符
//21~2F 33~47 !"#$%&'()*+,-./
if(window.event.keyCode >= 33 && window.event.keyCode <= 47)
window.event.keyCode = 0;
//3A~40 58~64 :;<=>?@
else if(window.event.keyCode >= 58 && window.event.keyCode <= 64)
window.event.keyCode = 0;
//5B~60 91~96 [/]^_`
else if(window.event.keyCode >= 91 && window.event.keyCode <= 96)
window.event.keyCode = 0;
//7B~7E 123~126 {|}~
else if(window.event.keyCode >= 123 && window.event.keyCode <= 126)
window.event.keyCode = 0;
}
调用方法:
<tr>
<td class="tbt_td">交通状况:</td>
<td class="tbt_td" colSpan="3"><INPUT id="traffic" οnkeypress="checkTextValid(this, 198) " type="text" size="85" name="traffic"
runat="server"></td>
</tr>
<tr>
<td class="tbt_td">楼盘户型:</td>
<td class="tbt_td" colSpan="3"><textarea οnkeypress="checkTextValid(this, 498)" id="flat" οnblur="if (this.value ==''){this.value='请输入楼盘户型'}"
style="WIDTH: 400px; HEIGHT: 60px" οnclick="if(this.value=='请输入楼盘户型')this.value=''" name="flat" runat="server">请输入楼盘户型</textarea>
<br>
<A οnclick="selectKeyword('flat','户型')" href="javascript:void(0)">选择楼盘户型</A>
</td>
</tr>
{
//检查文本内容长度
if(control.value.length >= length)
window.event.keyCode = 0;
//过滤特殊字符
//21~2F 33~47 !"#$%&'()*+,-./
if(window.event.keyCode >= 33 && window.event.keyCode <= 47)
window.event.keyCode = 0;
//3A~40 58~64 :;<=>?@
else if(window.event.keyCode >= 58 && window.event.keyCode <= 64)
window.event.keyCode = 0;
//5B~60 91~96 [/]^_`
else if(window.event.keyCode >= 91 && window.event.keyCode <= 96)
window.event.keyCode = 0;
//7B~7E 123~126 {|}~
else if(window.event.keyCode >= 123 && window.event.keyCode <= 126)
window.event.keyCode = 0;
}
调用方法:
<tr>
<td class="tbt_td">交通状况:</td>
<td class="tbt_td" colSpan="3"><INPUT id="traffic" οnkeypress="checkTextValid(this, 198) " type="text" size="85" name="traffic"
runat="server"></td>
</tr>
<tr>
<td class="tbt_td">楼盘户型:</td>
<td class="tbt_td" colSpan="3"><textarea οnkeypress="checkTextValid(this, 498)" id="flat" οnblur="if (this.value ==''){this.value='请输入楼盘户型'}"
style="WIDTH: 400px; HEIGHT: 60px" οnclick="if(this.value=='请输入楼盘户型')this.value=''" name="flat" runat="server">请输入楼盘户型</textarea>
<br>
<A οnclick="selectKeyword('flat','户型')" href="javascript:void(0)">选择楼盘户型</A>
</td>
</tr>