Shielding javascript code for a function of javascript in textarea

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.