【问题标题】:Need a hand with a non-working JQuery function需要一个不工作的 JQuery 函数
【发布时间】:2020-12-25 22:06:02
【问题描述】:

我的 JQuery 函数应该修改隐藏表单字段的值,然后提交表单。但它不会。小提琴here.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  $(function(){
    // when clicking the submit button
    $('.findme').click(function(){

        // Get the value of the clicked a tag
        var index = $(this).attr("id");

        // Strip out the prefix, leaving only the id
        var usethisID = index.substring(index.indexOf("_")+1 );
        alert('Value to post: ' + usethisID) ;

        // Make a hidden form field and set its value to usethisID
        var x = document.createElement("INPUT");
        x.setAttribute("type", "hidden");
        x.setAttribute("name", "xid");
        x.setAttribute("id", "xid");
        x.setAttribute("value", usethisID);

        // submit the form
        $('#fruitform').submit();
        });
    });
</script>

【问题讨论】:

  • 显示您的表格 m8。
  • 还有 - 你是不是缺少 appendChild 或类似的东西 - 你把你的 X 放在哪里?
  • 喜欢$('#fruitform').append(x).submit();?
  • 是的,我可以看到 createElement 并不是专门在fruitform中创建隐藏字段。但不管怎样,它只是不提交。表单代码在phpfiddle.org/main/code/5g1s-s8vz

标签: jquery forms post submit hidden


【解决方案1】:

啊哈!它不会发布,因为我的 a 标签的 href 属性是空的......

【讨论】:

    猜你喜欢
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多