0

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

<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>
4

1 回答 1

0

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

于 2020-09-08T16:02:32.530 回答