JavaScript笔记-点击button提交form表单

x33g5p2x  于2022-03-10 转载在 Java  
字(1.0k)|赞(0)|评价(0)|浏览(482)

功能如下:

点击购买后,点击确定。

确定调用了一个js函数,提交form表达给后端

代码如下:

<div class="modal-footer">
	<button type="button" class="btn text-white border bg-dark" data-bs-dismiss="modal">取消</button>
	<button type="button" class="btn text-white border bg-dark" onclick="purchaseProduction()">确定</button>
</div>

对应的js代码如下:

<script>
    function purchaseProduction(){

        var fundId = document.getElementById("fundId").value;
		var purchaseMoney = document.getElementById("purchaseMoney").value;

		var params = {
			fundId: fundId,
			purchaseMoney: purchaseMoney
        }
        var temp = document.createElement("form");
        temp.action = "index.php?p=user&c=fund&a=confirmPurchase";
        temp.method = "post";
        temp.style.display = "none";
        for (var x in params) {
            var opt = document.createElement("input");
            opt.name = x;
            opt.value = params[x];
            temp.appendChild(opt);
        }
        document.body.appendChild(temp);
        temp.submit();
    }
</script>

相关文章

最新文章

更多