[英]Textarea open a pop-up when click using jQuery
我需要使用文本區域來鼓勵人們發表評論,但是在他們發表評論之前,他們需要先登錄或注冊。 通過使用類“ popup-login”單擊網址“#”,可以使用模式彈出窗口打開此登錄/注冊表單。
單擊(使用jQuery)時,如何使textarea打開該模式彈出式登錄窗口? 有任何想法嗎?
創建一個打開模態的function
。 然后,使用onClick
調用該函數:
function modal() { document.getElementById('textarea').value="This would open a modal window"; }
textarea { background-color: white; }
<div style="display:inline-block; position:relative;"> <textarea id="textarea" placeholder="Write a comment..."disabled></textarea> <div style="position:absolute; left:0; right:0; top:0; bottom:0;" onClick="modal()"></div> </div>
假設您已經設置了.popup-login
的click事件,則此代碼應該可以正常工作。
// We are using focus instead of click to prevent the user from tabbing onto the comment box
$('#comment').on('focus', function() {
$('.popup-login').click();
// This will remove focus from the comment box
$(this).blur();
});
這是一個完整的例子
$('#comment').on('focus', function() { $('.popup-login').click(); $(this).blur(); }); $('.popup-login').on('click', function() { alert('This is where the popup would be'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="#" class="popup-login">Login</a> <textarea id="comment"></textarea>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.