There is a textarea, And I want to block a function in this textarea focus,
This is to make this function invalid and make it valid again after removing the focus. How can this function be implemented ???
1st Floor
In your function, use document. activeElement to get the control that focuses on the current webpage. If this textarea is used, the function will not be executed.
2nd floor
Learn from meizz
Third floor
To meizz (plum blossom snow)
I use
Document. activeElement. tagName. toLowerCase ()! = 'Textea'
To determine the textarea control, but there are multiple textarea on the page,
I only want to block this function in one textarea. What should I do ???
What's more troublesome is that there is another hidden textarea. Except for the readonly attribute, other attributes are identical with the textarea. How can this problem be implemented ???
4th floor
Use onfocus and onblur events as function switches
<Body>
<Script language = "JavaScript">
Function disablefun ()
{
Window. myfun = null;
}
Function enablefun ()
{
Window. myfun = function ()
{
Showid. innerHTML + = "I'm active <br> ";
};
}
Function myfun ()
{
Showid. innerHTML + = "I'm active <br> ";
}
</Script>
<Form method = "get" name = search id = search target = "_ blank">
The myfun function is triggered every time you type the content. <br>
<Textarea name = "txa" rows = "5" cols = "20" onkeydown = "if (myfun) myfun ()"> </textarea>
<Hr>
<Br>
The myfun function is not triggered every time you press the button (the function is invalid when focusing and the function is valid when focusing) <br>
<Textarea name = "txa" rows = "5" cols = "20" onfocus = "disablefun ()" onblur = "enablefun ()" onkeydown = "if (myfun) myfun () "> </textarea>
</Form>
<Div id = showid>
</Div>
</Body>