防止第二次点击 [英] Preventing second click
问题描述
我有一个Web应用程序(除此之外)做大型SQL
Insert''s,
所以有时它需要一段时间,用户变得不耐烦并再次点击(或
只是双击),
所以相同的数据再次插入。
我在Javascript中想到了一些简单的解决方案。
类似于:
< input name = myBtn onclick =" this.disable = true;" />
和
< body onload =" if(document.myBtn.disabled)document.myBtn.disabled = false;"
/>
....
< / body>
你认为这可行吗?
(该输入不是提交按钮,当任何DB
交易完成时页面实际重新加载)
复杂化是< bodyand< input在不同的文件中,
,即按钮是否在孙子中。 < bodyform(孩子包括
包括祖父母的父母)。
他们真的共享一份文件吗? ?
或者有更好的解决方案吗?
请指教。
提前谢谢你,
Oleg。
我取得了一些进展,发现了一些有趣的事情:
1)我应该只使用onload =" if(btn_id.disabled)",而不是
适用于FireFox,但不适用于IE6 [我的目标],
我必须使用的地方:if(document.getElementById(''btn_Id'')。disabled )
2)由于某些原因总是返回false,即使我只是设置
< input name =" name1" ID = QUOT; btn_id" onclick =" disabled = true"(或
this.disabled = true)
我从未听说过重新加载页面会重置其任何属性并且
没有其他具有相同ID或名称的按钮。
3)另一个奇怪的事情是我不能在任何
onload或onclick,做:
onload =" if(btn_id.disabled){alert.window(''some text''); }"给出错误:
致命:文件SystemId未知;第16行;列-1;找不到功能:
window.alert
但运行得很好没有花括号
这对我来说似乎是一个问题。任何解决方法?
TIA,
Oleg。
" Oleg Konovalov" < ok ****** @ verizon.netwrote in message
news:mpHSg.12807
2G1.1696@trnddc07 ...
我有一个Web应用程序(其中包括)执行大型SQL
插入''s,
所以有时需要一段时间,用户会变得不耐烦并再次点击(或者
只需双击),
所以相同的数据再次插入。
我在想Javascript中的一些简单解决方案。
类似于:
< input name = myBtn onclick =" this.disable = true;" />
和
< body onload =" if(document.myBtn.disabled)document.myBtn.disabled = false;"
/>
...
< / body>
你认为这可行吗? br />
(该输入不是提交按钮,当任何DB
交易完成时页面实际重新加载)
复杂性是并且< bodyand< input在不同的文件中,
,即如果按钮在孙子中。 < bodyform(孩子
包括包含祖父母的父母)。
他们真的共享一份文件吗? ?
或者有更好的解决方案吗?
请指教。
谢谢你提前,
Oleg。
blockquote>
" Oleg Konovalov" < ok ****** @ verizon.netwrote in message
news:mpHSg.12807
Hi,
I have a web application which is (among other things) doing large SQL
Insert''s,
so sometimes it takes a while, user becomes impatient and clicks again (or
just does double-click),
so the same data is getting inserted again.
I was thinking of some simple solution in Javascript.
something like:
<input name=myBtn onclick="this.disable=true;" />
and
<body onload="if (document.myBtn.disabled) document.myBtn.disabled=false;"
/>
....
</body>
Do you think that might work ?
(that input is not a Submit button, the page actually reloads when any DB
transaction is done)
The complication is that the <bodyand <inputare in different files,
i.e. if the button is in the "grandchild" of the <bodyform (child includes
the parent which includes a grandparent).
Do they really share a "document" ?
Or is there a nicer solution ?
Please advise.
Thank you in advance,
Oleg.
解决方案I have made some progress and found a few interesting things:
1) I should use just onload="if (btn_id.disabled)", not
onload="if(document.formname.btnname.disabled);" on grandparent form; That
works in FireFox, but not IE6 [which I target],
where I had to use: if(document.getElementById(''btn_Id'').disabled)
2) for some reason that always returns false, even if I just set
<input name="name1" id="btn_id" onclick="disabled=true"(or
this.disabled=true )
I have never heard that reloading a page resets any of its attributes and
there are no other buttons with the same id or name.
3) the other strange thing is that I can''t use any curly braces in any
onload or onclick, doing:
onload="if (btn_id.disabled) { alert.window(''some text''); }" gives error:
Fatal: File SystemId Unknown; Line 16; Column -1; Could not find function:
window.alert
but runs just fine without curly braces
That looks like a problem to me. Any workarounds ?
TIA,
Oleg.
"Oleg Konovalov" <ok******@verizon.netwrote in message
news:mpHSg.12807
2G1.1696@trnddc07...Hi,
I have a web application which is (among other things) doing large SQL
Insert''s,
so sometimes it takes a while, user becomes impatient and clicks again (or
just does double-click),
so the same data is getting inserted again.
I was thinking of some simple solution in Javascript.
something like:
<input name=myBtn onclick="this.disable=true;" />
and
<body onload="if (document.myBtn.disabled) document.myBtn.disabled=false;"
/>
...
</body>
Do you think that might work ?
(that input is not a Submit button, the page actually reloads when any DB
transaction is done)
The complication is that the <bodyand <inputare in different files,
i.e. if the button is in the "grandchild" of the <bodyform (child
includes the parent which includes a grandparent).
Do they really share a "document" ?
Or is there a nicer solution ?
Please advise.
Thank you in advance,
Oleg.
"Oleg Konovalov" <ok******@verizon.netwrote in message
news:mpHSg.12807
这篇关于防止第二次点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!