<input type="text" height=18 name="num" id="num" value="" onChange="if(parseInt(this.value)<0){
alert('wrong');this.value='';num.focus();}" >
为什么focus不到相应的文本框?
alert('wrong');this.value='';num.focus();}" >
为什么focus不到相应的文本框?
<input type="text" height=18 name="num" id="num" value=""
onkeyup="if(parseInt(this.value) <0){ alert('wrong');this.value='';num.focus();}">
返回由字符串转换得到的整数。parseInt(numString, [radix])参数
numString 必选项。要转换为数字的字符串。radix
可选项。在 2 和 36 之间的表示 numString 所保存数字的进制的值。如果没有提供,则前缀为 '0x' 的字符串被当作十六进制,前缀为 '0' 的字符串被当作八进制。所有其它字符串都被当作是十进制的。说明parseInt 方法返回与保存在 numString 中的数字值相等的整数。如果 numString 的前缀不能解释为整数,则返回 NaN(而不是数字)。 parseInt("abc") // 返回 NaN。
parseInt("12abc") // 返回 12。
可以用 isNaN 方法检测 NaN。
alert('wrong');this.value='';this.focus();}" > 试试
function check(e){
if(parseInt(e.value) <0){
alert('wrong');
e.value='';
setTimeout(function(){setfocus(e);}, 50);
}
}
function setfocus(e){
e.focus();
}
</script> </HEAD> <BODY>
<form name="form1">
<input type="text" height=18 name="num" id="num" value="" onchange="check(this);" />
<input type="text" height=18 name="num2" id="num2" value="" onchange="check(this);" />
</form>
</BODY>
<input type="text" height=18 name="num" id="num" value="" onkeyup="if(parseInt(this.value) <0){
alert('wrong');this.value='';this.focus();}" >