开发者

Alert is showing two times. how to restrict?

开发者 https://www.devze.com 2022-12-30 06:41 出处:网络
<script language=\"Javascript\"> function test(myObject, flag) { if ( (flag) || ((event.keyCode == 59) || (event.which == 59)) || ((event.keyCode == 44) || (event.which == 44)))
<script language="Javascript">  

function test(myObject, flag)
{
if ( (flag) || ((event.keyCode == 59) || (event.which == 59)) || ((event.keyCode == 44) || (event.which == 44)))
{alert(myObject.value);}
}      
function closeWin()
{self.close();}      
</script>            

<form name='test'>          
<textarea  name='textareaName' cols='44' rows='3' onChange='test(this, true);' --onKeyPress='test(this);' onBlur='test(this, true);' ></textarea>                           
<input type='text' name='textName'>      
<input type='button' name='buttonName' onclick='closeWin();' value='Cancel'>
</form>

开发者_运维问答I have a problem: when input value(e.g: test;) into textareaName field, the test function is always run more one time. Please show me the way can run this only one time.


Because you are adding the test function to onKeyPress (so every key press), onChange (so every time it changes), and onBlur (whenever you move to another field)

It is doing exactly what you told it to do, you should remove one of the event handlers.

0

精彩评论

暂无评论...
验证码 换一张
取 消