日期:2014-05-16  浏览次数:20304 次

一个简单的javascript事件问题
我在页面上有一个 <div> , <div> 上有一个文本框。我想让文本框显示或隐藏的时候执行一个已定义好的函数,请问该使用什么事件?请各位帮忙了!

------解决方案--------------------
文本框又不会自己隐藏,你在隐藏的时候调用一下函数就是了
------解决方案--------------------
楼上说的对,你在设置文本框显示或隐藏的同时调用以下函数不就行了
------解决方案--------------------
W3C标准里好像没有这个事件。
由于隐藏和显示只可能通过代码执行, 而不可能像onclick一样通过用户交互引发, 因此根本不需要这个事件。
要做的只是在隐藏和显示时同时调用相关的代码。
------解决方案--------------------
自己用htc定义一个事件
------解决方案--------------------
<form name=form1 METHOD=POST id=form1 action= "data_action_submit.asp " >
<div id= "a " name= "a " style= "display:none;width:80px;height:80px;background:yellow "

onpropertychange= "here() "> </div>
<input type= "button " value= "change the sytle of div " onclick= "a.style.display= 'block ' " />
</form>
<script>
function here()
{
alert( "div 's property of style has been changed ");
}
</script>
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> New Document </title>
<meta name= "Generator " content= "EditPlus ">
<meta name= "Author " content= " ">
<meta name= "Keywords " content= " ">
<meta name= "Description " content= " ">
</head>

<body>
<form method=post action= " ">
<DIV ALIGN= " " id= "div1 "> <input type= "text " name= " "> </DIV>
<input type= "button " onclick= "hiddenorShow(); ">
</form>
</body>
</html>
<script language= "JavaScript1.2 ">
<!--
function hiddenorShow()
{
if (document.all.div1.style.display== " ")
{
document.all.div1.style.display= "none ";
test();
}
else
{
document.all.div1.style.display= " ";
test();
}

}
function test()
{
alert( "test ");
}
//-->
</script>