问题描述
我的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>
解决方法
啊哈!它不会发布,因为我的标签的href属性为空...。