本文介绍了如何阻止此操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多文本框表格中,链接到外部js,我使用onBlur来调用:


函数chkNum(cellname){

var str = document.getElementById(cellname).value.toString(10);

if(str< 28 || str> 36){alert("输入的温度超出范围。) ;);

返回;}

}


我将数据输入第一个文本框并将光标移动到第二个

文本框。正确调用该函数。由于textbox2为空,当我将光标移回textbox1时,我再次(适当地)获取警报。

如何防止这种情况?


-

Ed Jay(删除M以通过电子邮件回复)

On a multi-textbox form, linked to an external js, I use onBlur to call:

function chkNum(cellname) {
var str = document.getElementById(cellname).value.toString(1 0);
if (str < 28 || str > 36) {alert("Temperature entered is out of range.");
return;}
}

I enter data into the first textbox and move the cursor to the second
textbox. The function is properly called. Since textbox2 is empty, when I
move the cursor back to textbox1, I again (appropriately) get the alert.
How can I prevent this?

--
Ed Jay (remove M to respond by email)

推荐答案



^^^ ^^^

使用更改事件并验证以响应提交事件。


应谨慎使用模糊事件。太多的东西都可能导致

控制失去焦点,因此如果用户/他们/更改了某个值并进入了价值无效。


[snip]


Mike


-

Michael Winter

在通过电子邮件回复之前使用[新闻]进行前缀主题。


^^^^^^
Use the change event and validate in response to the submit event, too.

The blur event should be used sparingly. Too many things can cause a
control to lose focus, so it''s kinder to the user to only bug them if
they /changed/ a value and entered an invalid value.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.





设置范围内文本框的值。


< input type =" text"值= QUOT; 28" .....>


-

兰迪

comp.lang.javascript常见问题 - &新闻组每周

Javascript最佳实践 -



Set the value of the textbox within range.

<input type="text" value="28" .....>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/




Don对布鲁尔进行审计。请改用onChange。



Don''t audit onBlur. Use onChange, instead.




Lee,Mike,Randy ...非常感谢。


-

Ed Jay(删除M以通过电子邮件回复)



Lee, Mike, Randy...Thanks very much.

--
Ed Jay (remove M to respond by email)


这篇关于如何阻止此操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 18:17