FORM和javascript.location [英] FORM and javascript.location

查看:73
本文介绍了FORM和javascript.location的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个asp页面,其中我动态填写表格的ACTION属性

。问题是,无论何时我尝试使用javascript :位置重定向到html

页面,它都会被重定向到

位置尽管分配给javascript的location属性的是

,但是表单元素的ACTION属性。


< FORM NAME =" CRYSTFORM" METHOD = POST ACTION =<%= thisPage%>>








< / FORM>

< button onClick =" javascript :location =''<%= goBackToURL%>''" ;; id = butto n1

name = button1OK< / button>

我在表单中间使用div标签来控制
$ b $的可见性b某些视觉元素。


非常感谢任何帮助。

提前致谢,

John。

I am using an asp page in which i dynamically fill the ACTION property
of the form. The problem is that whenever i try to redirect to a html
page using the javascript:location, it is getting redirected to the
location in the ACTION attribute of the form element despite what is
assigned to the location attribute of the javascript.

<FORM NAME="CRYSTFORM" METHOD=POST ACTION=<%=thisPage%>>
:
:
:

</FORM>
<button onClick ="javascript:location=''<%=goBackToURL%>''";id=butto n1
name=button1OK </button>
I am using div tags in middle of the form to control the visibility of
certain visual elements.

Any help would be greatly appreciated.
Thanks in advance,
John.

推荐答案

于2006年9月9日在microsoft.public.inetserver.asp.general上写道:
wrote on 09 sep 2006 in microsoft.public.inetserver.asp.general:

我正在使用一个asp页面,其中我动态填写表格的ACTION属性

。问题是,无论何时我尝试使用javascript :位置重定向到html

页面,它都会被重定向到

位置表单元素的ACTION属性,尽管分配给javascript的location属性的是

I am using an asp page in which i dynamically fill the ACTION property
of the form. The problem is that whenever i try to redirect to a html
page using the javascript:location, it is getting redirected to the
location in the ACTION attribute of the form element despite what is
assigned to the location attribute of the javascript.



是的,但不是如你所示,只有当按钮元素在(!!!)

表格内时,提交可以首先点火

yes, but not as you showed, only if the button element is inside(!!!) the
form, the submit could fire first


>

< FORM NAME =" CRYSTFORM" METHOD = POST ACTION =<%= thisPage%>>
>
<FORM NAME="CRYSTFORM" METHOD=POST ACTION=<%=thisPage%>>



如果此页面中有空格

值,请使用客户端报价。使用单个quptes客户端以获得清晰度。


尝试:


< form name =''crystform''method =''post'' action =''<%= thispage%>''>

use clientside quotes for the case that there is a space in the thispage
value. use single quptes clientside for clarity.

Try:

<form name = ''crystform'' method = ''post'' action = ''<% = thispage %>''>









< / FORM>


< button onClick =" javascript :location ='' <%= goBackToURL%>''" ;; id = butto n1

name = button1OK< / button>
:
:
:

</FORM>
<button onClick ="javascript:location=''<%=goBackToURL%>''";id=butto n1
name=button1OK </button>



不使用;在javascript字符串之外


onClick需要javascript [如果没有使用客户端的vbs],

所以不要添加javascript :部分。


如果在表单内,请尝试添加type =''button'。


< button type =''button''

onClick =" location.href =''<%= goBackToURL%>'';"

id =''button1''

name =''button1''>

返回

< / button>

do not use a ; outside the javascript string

onClick expects javascript [if no clientsided vbs is used],
so do not add the javascript: part.

Try adding type=''button'' if inside a form.

<button type=''button''
onClick ="location.href=''<%=goBackToURL%>'';"
id=''button1''
name=''button1''>
go back
</button>


我在表单中间使用div标签来控制

某些视觉元素的可见性。
I am using div tags in middle of the form to control the visibility of
certain visual elements.



与你的问题无关,John。


-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)

not related to your problem, John.

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


jo ********* @ gmail.com 写道:

我正在使用一个asp页面,其中我动态填写表格的ACTION属性

。问题是,无论何时我尝试使用javascript :位置重定向到html

页面,它都会被重定向到

位置尽管分配给javascript的location属性的是

,但是表单元素的ACTION属性。


< FORM NAME =" CRYSTFORM" METHOD = POST ACTION =<%= thisPage%>>
I am using an asp page in which i dynamically fill the ACTION property
of the form. The problem is that whenever i try to redirect to a html
page using the javascript:location, it is getting redirected to the
location in the ACTION attribute of the form element despite what is
assigned to the location attribute of the javascript.

<FORM NAME="CRYSTFORM" METHOD=POST ACTION=<%=thisPage%>>

>>

>>



< / FORM>


< button onClick =" javascript :location =''<%= goBackToURL%>''" ;; id = butto n1

name = button1OK< / button>


</FORM>
<button onClick ="javascript:location=''<%=goBackToURL%>''";id=butto n1
name=button1OK </button>



我首先要摆脱使用javascript

伪协议的习惯。 HTML规范要求浏览器将ONCLICK属性的内容交给脚本引擎:


onclick = script [CT]
http://www.w3.org/TR/ html4 / interact / ... l#adef-onclick


....和...


用户代理不得将脚本数据评估为HTML标记,但是

必须将其作为数据传递给脚本引擎。
http://www.w3.org/TR/html4/types.html#type-script


在我看来,如果你使用的是javascript :伪协议,那么你做错了什么就是
。更多信息: http://jibbering.com/faq/#FAQ4_24


但真正的问题是你没有意识到默认情况下,BUTTON

元素与INPUT TYPE =submit相同:


17.5 BUTTON元素

type = submit | button | reset [CI]

此属性声明按钮的类型。

可能的值:

* submit:创建一个提交按钮。这是

的默认值。

* reset:创建一个重置按钮。

*按钮:创建一个按钮。

http:// www。 w3.org/TR/html4/interact/...ml#edef-BUTTON


解决方案包括:


- 使用TYPE ="按钮"属性

- 通过防止来自传播的点击操作来取消表单的操作:

onclick =" location =''< %= goBackToURL%>'';返回false"

- 更改为INPUT TYPE ="按钮"

- 使用锚点:< a href =" <%= goBackToURL%>">

-

Dave Anderson


将阅读未经请求的商业电子邮件每个消息的成本为

I would start by getting out of the habit of using the javascript:
pseudo-protocol. The HTML specification requires the browser to hand the
contents of ONCLICK attributes to a scripting engine:

onclick = script [CT]
http://www.w3.org/TR/html4/interact/...l#adef-onclick

....and...

User agents must not evaluate script data as HTML markup but
instead must pass it on as data to a script engine.
http://www.w3.org/TR/html4/types.html#type-script

In my opinion, if you are using the javascript: pseudo-protocol, you are
doing something wrong. More here: http://jibbering.com/faq/#FAQ4_24

But the real issue is that you did not realize that by default, the BUTTON
element is the same as an INPUT TYPE="submit":

17.5 The BUTTON element
type = submit|button|reset [CI]
This attribute declares the type of the button.
Possible values:
* submit: Creates a submit button. This is the
default value.
* reset: Creates a reset button.
* button: Creates a push button.

http://www.w3.org/TR/html4/interact/...ml#edef-BUTTON

Solutions include:

- Use the TYPE="button" attribute
- Cancel the action of the form by preventing
the click action from propogating:
onclick="location=''<%=goBackToURL%>'';return false"
- Change to INPUT TYPE="button"
- Use an anchor: <a href="<%=goBackToURL%>">
--
Dave Anderson

Unsolicited commercial email will be read at a cost of


500。使用
这个电子邮件地址的
表示同意这些条款。
500 per message. Use
of this email address implies consent to these terms.


这篇关于FORM和javascript.location的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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