【问题标题】:Is it possible to add an anchor to a FORM post/get?是否可以在 FORM 帖子/获取中添加锚点?
【发布时间】:2010-10-16 03:58:07
【问题描述】:

我注意到在 Firefox 中我可以将 #MyAnchor 标记添加到 action 属性中,例如...

<form action="#MyAnchor">
   <input type="text" name="a" />
   <input type="text" name="b" />
   <input type="submit" />
</form>

当表单提交时,锚点会自动显示在 URL 中

mypage.aspx?a=1&b=2#MyAnchor

但是,这在 IE 上不起作用。无论如何,我可以为这两种浏览器找到一个快乐的媒介吗?

【问题讨论】:

    标签: html forms input submit


    【解决方案1】:

    我用它来跨回发保留片段:

        var f = document.forms[0];
        var index = f.action.indexOf("#");
        if(index>0)
            f.action = f.action.substr(0,index) + "#" + tabId;
        else
            f.action += "#" + tabId;
    

    【讨论】:

      【解决方案2】:

      您可以在客户端或服务器端处理此问题:

      在服务器端:添加一个以锚点为值的隐藏元素,并在服务器上构建的 URL 上进行重定向。

      在客户端:例如,jQuery 允许您将表单的参数序列化为 URL;您只需要附加锚点并将其分配给 window.location。

      【讨论】:

        【解决方案3】:

        只是猜测,但您是否尝试过使用页面 + 锚名称。

        <form action="mypage.aspx#MyAnchor">
        

        【讨论】:

        • 你在哪个版本的 IE 上测试这个?
        • 您是否在 javascript 或回发中执行任何操作?
        猜你喜欢
        • 2023-04-02
        • 2016-08-24
        • 1970-01-01
        • 1970-01-01
        • 2018-04-01
        • 1970-01-01
        • 2022-07-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多