当表单操作属性为“#”时,这意味着什么? (数字/磅符号/符号/字符)? [英] What does it mean when the form action attribute is "#" (number/pound symbol/sign/character)?

查看:127
本文介绍了当表单操作属性为“#”时,这意味着什么? (数字/磅符号/符号/字符)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当形式 action 属性是#(数字/磅符号/符号/字符)时,这意味着什么?

当表单输入的 formaction 属性设置为#时会发生什么?这是否阻止输入提交给服务器?

 < form method =GETaction =example.php > 
< input type =textsize =20name =text1value =text1formaction =#/>
< input type =textsize =20name =text2value =text2/>
< input type =submitvalue =Submit/>
< / form>


解决方案

#作为URL引用(无论作为动作还是 formaction 属性值或其他)是参考到当前基础文档的开始。除非已设置< base href = ...> 标签,否则基本文档是当前文档。



发生什么事情取决于情况。通常,浏览器再次使用URL中的查询部分请求页面(并再次加载页面,这可能意味着运行客户端脚本),但如果之前使用过相同的查询,浏览器可能会使用它的缓存。而且,当文档被引用时,关注任何表单元素都会丢失,并且页面可能会向后滚动。

因此尽管在某些编码风格中相当常见,它不可靠。使用客户端事件处理程序可以更好地实现其目的。


$ b formaction 属性仅适用于提交按钮。文本输入元素不构成提交按钮,即使它可能会触发表单提交,所以在这里该属性被忽略。


What does it mean when the form action attribute is "#" (number/pound symbol/sign/character)?

What happens when a form input's formaction attribute is set to "#"? Does this prevent the input from being submitted to the server?

<form method="GET" action="example.php">
    <input type="text" size="20" name="text1" value="text1" formaction="#"/>
    <input type="text" size="20" name="text2" value="text2"/>
    <input type="submit" value="Submit"/>
</form>

解决方案

The meaning of # as a URL reference (whether as action or formaction attribute value or otherwise) is a reference to the start of the current base document. The base document is the current document, unless a <base href=...> tag has been set.

What happens depends on the situation. Typically, the browser requests for the page again with a query part in the URL (and the page is loaded again, which may imply that client-side scripts are run), but if the same query had been used earlier, the browser probably uses its cache. Moreover, as the start of the document is referred to, focus on any form element is lost and the page may scroll backwards.

So although # is fairly common in some coding styles, it is not reliable; its purpose is better achieved using client-side event handlers.

The formaction attribute has a meaning only for submit buttons. A text input element does not constitute a submit button, even though it may trigger form submission, so here the attribute is ignored.

这篇关于当表单操作属性为“#”时,这意味着什么? (数字/磅符号/符号/字符)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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