问题描述
我有一个链接,打开一个新的页面,我想知道是否有一种方法,该链接只能点击一次,所以表单不能提交多次。
I have a link that opens a new page and I was wondering if there was a way that would make the link only click-able once so the form cannot be submitted numerous times.
<div id="addSection"><a class="addSection"
onclick="javascript:writeBookmark(this); var newwin = window.open('<c:url value="/URL_WINDOW"/>',
'additional', 'width=400,height=280,toolbar=no,,menubar=no,scrollbars=yes,resizeable=no'); newwin.focus(); return null;">
Add sub
我有JavaScript使用按钮,但不知道如何做当我不处理按钮。
I have JavaScript to do this with buttons but not sure how to do it when I am not dealing with buttons.
推荐答案
首先,我会移动你的点击处理程序,然后,我将添加一些代码到处理程序,以删除链接本身或替换的点击处理程序与一个弹出一个消息,该链接只能使用一次。
First, I would move your click handler so that it's not applied inline. Then, I would add some code to the handler to either remove the link itself or replace the click handler with one that pops up a message that the link can only be used once.
示例(使用jQuery)
Example (using jQuery)
$('.addSection').on('click', function(e) {
e.preventDefault();
writeBookmark(this);
var newwin = window.open('<c:url value="/URL_WINDOW"/>',
'additional',
'width=400,height=280,toolbar=no,,menubar=no,scrollbars=yes,resizeable=no');
newwin.focus();
$(this).off('click').on('click', function() {
alert('You've already performed this action');
});
});
这篇关于只需要一个链接可以点击一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!