Safari进入/返回绕过我的按钮脚本 [英] Safari enter/return bypassing my button script

查看:60
本文介绍了Safari进入/返回绕过我的按钮脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单和一个按钮来提交它。该按钮来自:

< input type = button onclick =''myHandler(this.form);''>


这一切都很好,除了在Safari 2.0.4中输入/返回键,

如果按下,提交表格 - 绕过我的onclick处理程序。


我可以部分解决这个问题:


< form onsubmit =''返回false;''>


除了如果在按下时间输入/返回,焦点在我的表单中的iframe的一个

,然后重新加载iframe(当然有高飞

参数)。如果按下输入/返回时无关紧要,那么这些就会被忽略OK。


请注意,使用Firefox Mac和任何WIndows浏览器,返回似乎被忽略了



如果输入/返回

,我怎样才能阻止Safari提交表单?


谢谢,

I have a form and a button to submit it. The button is made from:

<input type=button onclick=''myHandler(this.form);''>

This all works fine except that in Safari 2.0.4, the enter/return keys,
if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit=''return false;''>

except that if at the time enter/return is pressed, the focus is on one
of the iframes in my form, then the iframe gets reloaded (with goofy
parameters, of course). If the focus is nowhere when enter/return is
pressed, then these get ignored OK.

Note that with Firefox Mac and any WIndows browser, return seems to be
ignored.

How can I prevent Safari from submitting the form when enter/return are
pressed?

Thanks,

推荐答案

Tim Streater< ti ********** @ dante .org.ukwrote在

新闻:ti ******************************** @ news .indiv idual.net:
Tim Streater <ti**********@dante.org.ukwrote in
news:ti********************************@news.indiv idual.net:

我有一个表单和一个按钮来提交它。该按钮来自:

< input type = button onclick =''myHandler(this.form);''>


一切正常,但在Safari 2.0.4中,输入/返回

键,如果按下,则提交表格 - 绕过我的onclick处理程序。


我可以部分解决这个问题:


< form onsubmit =''return false;''>
I have a form and a button to submit it. The button is made from:

<input type=button onclick=''myHandler(this.form);''>

This all works fine except that in Safari 2.0.4, the enter/return
keys, if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit=''return false;''>



首先,虽然这不是你问题的原因,你不能期望

javascript正常工作你的(X)HTML标记很糟糕。你的按钮

脚本应该是< input type =" button" onclick =" myHandler(this.form);">

(输入类型的引号)。


毫无疑问你会发现javascript的行为奇怪的是,如果你的文件不是
有效。


除此之外,为什么你不能把myHandler函数放在表单提交上?

这会解决Safari的问题吗?


< form onsubmit =" return myHandler(this);">

First off, though this isn''t the reason for your problem, you can''t expect
javascript to work properly if your (X)HTML markup is bad. Your button
script should be <input type="button" onclick="myHandler(this.form);">
(quotes around the input type).

You will no doubt find javascript behaving oddly if your document isn''t
valid.

That aside, why can''t you put the myHandler function on the form submit?
Will that solve the Safari problem?

<form onsubmit="return myHandler(this);">


Good Man在2007年6月12日上午11:56发表以下内容:
Good Man said the following on 6/12/2007 11:56 AM:

Tim Streater< ti ****** ****@dante.org.ukwrote在

新闻:ti **************************** ****@news.indiv idual.net:
Tim Streater <ti**********@dante.org.ukwrote in
news:ti********************************@news.indiv idual.net:

>我有一个表单和一个按钮来提交它。该按钮来自:
< input type = button onclick =''myHandler(this.form);''>

这一切都正常,除了在Safari 2.0.4,输入/返回
键,如果按下,则提交表单 - 绕过我的onclick处理程序。

我可以部分解决这个问题:

< form onsubmit =''return false;''>
>I have a form and a button to submit it. The button is made from:

<input type=button onclick=''myHandler(this.form);''>

This all works fine except that in Safari 2.0.4, the enter/return
keys, if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit=''return false;''>



首先,虽然这不是你问题的原因,你不能期望

javascript正常工作你的(X)HTML标记很糟糕。


First off, though this isn''t the reason for your problem, you can''t expect
javascript to work properly if your (X)HTML markup is bad.



没有什么坏的或无效或无效关于那个HTML。

属性唯一需要引用*是否有空格或其他

特殊字符。

There is nothing "bad" or "invalid" about that HTML. The only time
attributes are *required* to be quoted is if they have a space or other
special characters in them.


您的按钮脚本应为< input type =" button" onclick =" myHandler(this.form);">

(输入类型的引号)。
Your button script should be <input type="button" onclick="myHandler(this.form);">
(quotes around the input type).



废话。发布的代码验证得很好。

Nonsense. The code posted validates just fine.


如果您的文档不是有效的,那么毫无疑问会发现javascript表现得很奇怪。
You will no doubt find javascript behaving oddly if your document isn''t
valid.



现在这是真的,但这不是问题因为它无关紧要。

Now that is true but it isn''t the problem here as it is irrelevant.


除此之外,为什么你不能将myHandler函数放在表单提交上?
That aside, why can''t you put the myHandler function on the form submit?



因为表单提交甚至处理程序可能不会做你想要的东西。

唯一可以解雇的方法就是提交形式,并不总是需要
。如果myHandler只设置输入的

值,那将非常疯狂。


-

Randy

机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html

Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/


文章< Xn ** **********************@216.196.97.131> ;,

好​​人< he *** @ letsgo.comwrote:
In article <Xn************************@216.196.97.131>,
Good Man <he***@letsgo.comwrote:

Tim Streater< ti ********** @ dante.org.ukwrote

news:ti * *******************************@news.indiv idual.net:
Tim Streater <ti**********@dante.org.ukwrote in
news:ti********************************@news.indiv idual.net:

我有一个表单和一个按钮来提交它。该按钮来自:

< input type = button onclick =''myHandler(this.form);''>


一切正常,但在Safari 2.0.4中,输入/返回

键,如果按下,则提交表格 - 绕过我的onclick处理程序。


我可以部分解决这个问题:


< form onsubmit =''return false;''>
I have a form and a button to submit it. The button is made from:

<input type=button onclick=''myHandler(this.form);''>

This all works fine except that in Safari 2.0.4, the enter/return
keys, if pressed, submit the form - bypassing my onclick handler.

I can partially fix this with:

<form onsubmit=''return false;''>



首先,虽然这不是你问题的原因,你不能期望

javascript正常工作你的(X)HTML标记很糟糕。你的按钮

脚本应该是< input type =" button" onclick =" myHandler(this.form);">

(输入类型的引号)。


First off, though this isn''t the reason for your problem, you can''t expect
javascript to work properly if your (X)HTML markup is bad. Your button
script should be <input type="button" onclick="myHandler(this.form);">
(quotes around the input type).



你是说这些:


< form onsubmit =''return false;''>

< form onsubmit =" return false;">


不等价?

Are you saying that these:

<form onsubmit=''return false;''>
<form onsubmit="return false;">

are not equivalent?


除此之外,为什么你不能把myHandler函数放在表单提交上?

这会解决Safari的问题吗?


< form onsubmit =" return myHandler(this);">
That aside, why can''t you put the myHandler function on the form submit?
Will that solve the Safari problem?

<form onsubmit="return myHandler(this);">



我确实尝试了这个但它没有用 - 可能是因为我没有这样做

正确(离开表格) 。在那里提交等等)。我必须这样做才能更加仔细地看看我是如何上班的。


如果我可以禁用,我会更喜欢我的解决方案返回做提交的
效果 - 但无论如何。


有趣的是,从我在JavaScript圣经中读到的内容我还剩下来了

返回/输入密钥*应该*提交的印象 - 但是

Safari似乎是唯一一个这样做的。


谢谢,

I did try this but it didn''t work - probably because I didn''t do it
properly (left the form.submit in there etc etc). I''ll have to do it
more carefully and see how I get on.

I would have preferred my solution if I could have made that disable the
effect of return doing a submit - but anyway.

Funnily enough, from what I read in the JavaScript Bible I was left with
the impression that the return/enter key *should* do a submit - but
Safari seems the only one that does that.

Thanks,


这篇关于Safari进入/返回绕过我的按钮脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆