求一个javascript的select中onchange事件的解决方法!
<HTML >
<head >
<SCRIPT language="javascript" >
function showpublishtel()
{
if(document.getElementById("age").value=="18")
{
name.innerText="DEF:"
}
if(16==document.getElementById("age").value=="16")
{
name.innerText="ABC:"
}
}
</SCRIPT >
</HEAD >
<BODY >
<form name="form" action="" method="post" >
<table >
<div id="name" >年龄: </div >
<td >
<SELECT id="age" name="age" onchange="showpublishtel();" >
<OPTION value=16 >16岁 </OPTION >
<OPTION value=18 >18岁 </OPTION >
<OPTION value=20 >20岁 </OPTION >
</select >
</td >
</table >
</form >
</BODY >
</HTML >
就是当我选择16岁时候,id是name插入文本"ABC"
当我选择18岁时候 id是name插入文本"DEF" 替换掉“年龄”
大家看下我哪写错了,现在什么都出不来!!
------解决方案--------------------<HTML>
<head>
<SCRIPT language="javascript">
function showpublishtel()
{
if(document.getElementById("age").value=="18")
{
document.getElementById("name").innerText="DEF:"
}
if(16==document.getElementById("age").value=="16")
{
document.getElementById("name").innerText="ABC:"
}
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form" action="" method="post">
<table >
<div id="name">年龄: </div>
<td>
<SELECT id="age" name="age" onchange="showpublishtel();">
<OPTION value=16>16岁 </OPTION>
<OPTION value=18>18岁 </OPTION>
<OPTION value=20>20岁 </OPTION>
</select>
</td>
</table>
</form>
</BODY>
</HTML>
------解决方案--------------------1.name 这个没有定义。可以DOCUMENT。GETELEMENTBYID()获取对象。
2.if(16==document.getElementById("age").value=="16") 写错了,应该是if(document.getElementById("age").value=="16");
------解决方案--------------------<HTML >
<head >
<SCRIPT language="javascript" >
function showpublishtel()
{
var name = document.getElementById("name");
if(document.getElementById("age").value=="18")
{
name.innerText="DEF:" ;
}
if(document.getElementById("age").value=="16")
{
name.innerText="ABC:" ;
}
}
</SCRIPT >
</HEAD >
<BODY >
<form name="form" action="" method="post" >
<table >
<div id="name" >年龄: </div >
<td >
<SELECT id="age" name="age" onchange="showpublishtel()" >
<OPTION value=16 >16岁 </OPTION >