通过点击页面上的任何链接发送表单



站点必须通过klicking此站点上的任何链接来发送POST请求"amount=1"。

与GET一起工作:

window.onload = function () { document.body.onclick = function (e) { e = e||event; var was = (e.target||e.srcElement);
if ( was.href ) { was.href = was.href + '?edit=yes'; } }; };

但是我不想在url中有这个参数。

我的想法是:

<form action="" id="amount" method="POST">
<input name="amount" type="hidden" value="1"/>
<input type="submit" />
</form>

<script>
window.onload = function () { document.body.onclick = function (e) { e = e||event; var was = (e.target||e.srcElement);
if ( was.href ) {          document.amount.submit();        } }; };

但这是行不通的。

好吧,onclick不起作用,总是起作用,请参阅鼠标事件

因此,以下内容将适用于您。

window.onload = function() {
document.body.onmouseup = function(e) {
document.getElementById("amount").submit();
}
};
<body>
<form action="" id="amount" method="POST">
<input name="amount" type="hidden" value="1" />
<input type="submit" />
</form>
<span>this is in the body</span>
</body>

最新更新