[英]Ensure user clicked on dynamically generated external links before submitting
我需要確保用戶在提交之前必須單擊外部鏈接(會彈出一個新頁面)。
有沒有一種簡單的方法可以在所有主流瀏覽器上使用?
更新:這些鏈接中可能有幾個是動態生成的。 需要確保每個人都已被點擊
聲明一個全局變量:
window.clicked = false;
然后在鏈接的onclick上,執行以下操作:
<a href="some external link" onclick="clicked=true;">Hi</a>
現在,如果用戶單擊了外部鏈接,則clicked
將為true
否則為false
。
基於此,做你的邏輯
這對您有幫助嗎? 這是FIDDLE 。
<input type="submit" name="submit" value="Submit" disabled>
$(function() {
// For demo purposes
$('body').prepend('<a href="http://google.com" class="ext">Google</a>' +
'<a href="http://google.com" class="ext">Google</a>' +
'<a href="http://google.com" class="ext">Google</a>' +
'<a href="http://google.com" class="ext">Google</a>' +
'<a href="http://google.com" class="ext">Google</a>');
$(document).on('click','.ext', function() {
$(this).toggleClass('ext','clicked');
if($('.ext').length === 0) {
$('input[name="submit"]').prop('disabled',false);
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.