当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 在textarea中屏蔽js的某个function的javascript代码

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 在textarea中屏蔽js的某个function的javascript代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 79 ::
收藏到网摘: n/a

有一个textarea,我想在这焦点在这个textarea中的时候屏蔽某个function,
就是使这个function失效,移出焦点后重新使其有效,请问该怎样实现???
1楼
在你的那个函数里通过 document.activeElement 得到当前网页聚焦的那个控件, 判断这个若是这个 textarea 则跳出不执行本函数
2楼
楼上正解,向meizz学习
3楼
to meizz(梅花雪)
我是用
document.activeElement.tagName.toLowerCase()!='textarea'
来判断textarea控件的,可是页面上有多个textarea,
我只想在其中一个textarea中屏蔽此function,请问该如何做???
更麻烦的是另外有个hidden的textarea,除了属性是readonly外,其他属性和此textarea完全相同,请问又该如何实现???
4楼
使用onfocus,onblur事件作函数开关
<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">
每次键入内容均触发myfun函数<br>
<textarea name="txa" rows="5" cols="20" onkeydown="if(myfun)myfun()"></textarea>
<hr>
<br>
每次按键均不触发myfun函数(聚焦时失效,失焦时有效)<br>
<textarea name="txa" rows="5" cols="20" onfocus="disablefun()" onblur="enablefun()" onkeydown="if(myfun)myfun()"></textarea>
</form>
<div id=showid>
</div>
</body>