简体   繁体   English

如何在IE9中使用jQuery通过锚提交表单

[英]How to submit a form via anchor using jQuery in IE9

I have something to the effect of : 我有一些效果:

<a href="#" >click me</a>

And: 和:

$(document).ready(function() {
  $('a').click(function() {
    $('<form action="/" method="post"></form>').submit();
    return false;
  }
}

The expected result is that clicking the anchor will submit the form and redirect the page. 预期的结果是单击锚点将提交表单并重定向页面。 This works in Chrome and Firefox. 这适用于Chrome和Firefox。 In Internet Explorer 9, the browser just follows the link to #. 在Internet Explorer 9中,浏览器只是跟随#的链接。 Any solutions? 有解决方案吗

Try this 尝试这个

    $('a').click(function() { 
        var form = '<form action="/" method="post"></form>';
        $('body').append(form);
        $('form:last').submit();
    } );

I would try appending the form to the body first. 我会先尝试将表格附加到身体上。 However, why do you need a form at all? 但是,为什么你需要一个表格呢?

$(document).ready(function() {
  $('a').click(function() {
    $.post("/");
    return false;
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM