Home  >  Article  >  Web Front-end  >  Shield the javascript code of a certain function of js in textarea_form effects

Shield the javascript code of a certain function of js in textarea_form effects

WBOY
WBOYOriginal
2016-05-16 19:14:49981browse

There is a textarea. I want to block a certain function when the focus is in this textarea.
It means to invalidate this function and make it valid again after removing the focus. How to achieve this? ? ?
1st floor
In your function, use document.activeElement to get the control that the current webpage is focused on. If it is judged to be this textarea, it will jump out and not execute this function.
2nd floor
The correct answer is upstairs. meizz learning
3rd floor
to meizz (Mei Huaxue)
I use
document.activeElement.tagName.toLowerCase()!='textarea'
to judge the textarea control, but the page There are multiple textareas on
I only want to block this function in one of the textareas. How should I do it? ? ?
What’s even more troublesome is that there is another hidden textarea. Except for the readonly attribute, the other attributes are exactly the same as this textarea. How to implement it? ? ?
Floor 4
Use onfocus, onblur events as function switches





The myfun function is triggered every time you type something






The myfun function is not triggered every time the key is pressed (invalid when focused, valid when out of focus)

 
 
 
 
 
 
  
 <script> <BR> function disablefun() <BR> { <BR> window.myfun = null; <BR> } <BR> function enablefun() <BR> { <BR> window.myfun = function() <BR> { <BR> showid.innerHTML += "i'm active<br>"; <BR> }; <BR> } <BR> function myfun() <BR> { <BR> showid.innerHTML += "i'm active<br>"; <BR> } <BR> </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn