-1
我在兩個地方使用了HTMLelement.focus。一個在componentdidupdate中,一個在普通私有方法中。 componentdidupdate中的一個觸發引用元素的點擊操作。當我在調試模式下檢查流程時,點擊事件沒有被觸發。正常的私人方法中的一個工作正常。如何防止.focus在HTMLelement之後發生點擊事件?
如何防止焦點事件後的點擊?
我在兩個地方使用了HTMLelement.focus。一個在componentdidupdate中,一個在普通私有方法中。 componentdidupdate中的一個觸發引用元素的點擊操作。當我在調試模式下檢查流程時,點擊事件沒有被觸發。正常的私人方法中的一個工作正常。如何防止.focus在HTMLelement之後發生點擊事件?
如何防止焦點事件後的點擊?
儘管您不使用jQuery,但如果您想使用jQuery,只需使用jQuery焦點事件並關閉元素上的單擊事件即可。在這裏你可以看到#second
文本框......!
$(document).ready(function() {
\t $('#first, #second').on('click', function(event) {
\t \t event.preventDefault();
\t \t console.log('clicked..!')
\t });
\t $('#second').on('focus', function(event) {
\t \t event.preventDefault();
\t \t $(this).off('click');
\t });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="" id="first" placeholder="First">
<input type="text" name="" id="second" placeholder="second">
我正在使用React,不能在這裏使用jQuery。 – user1620492
歡迎SO - 請閱讀如何提問幫助部分。如果你展示你已經嘗試過的東西,那麼這很理想 –