想做一个select选项改变后,改变P标签里文字的效果,
因为表单是php自动生成的,value不能改。
就写成下面这样,发现选择后文字不能变化,
请问怎么改才能达到效果呢?
<html>
<head>
<script type="text/javascript">
function changeSelect(_select){
var _p = document.getElementById("p");
for(var i = 0; i < _p.childNodes.length; i ++){
_p.removeChild(_p.childNodes[i]);
}
if (_select.value=1)
{
var _tip = "选择了1"
}
else if (_select.value=2)
{
var _tip = "选择了2"
}
else
{
var _tip = "选择了3"
}
var _text = document.createTextNode(_tip);
_p.appendChild(_text);
}
</script>
</head>
<body>
<select onChange="changeSelect(this)">
<option/>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<p id="p">选择后这里的文字会改变</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title>yu.html</title>
<script type="text/javascript">
function changeSelect (_select)
{
var _p = document.getElementById ("p");
for ( var i = 0; i < _p.childNodes.length; i++)
{
_p.removeChild (_p.childNodes[i]);
}
差蠢 if (_select.value == '1'虚神陪)
{
var _tip = "选择了1";
}
else if (_select.value == '2')
{
var _tip = "选择了2";
}
else
{
var _tip = "选择了瞎弯3";
}
var _text = document.createTextNode (_tip);
_p.appendChild (_text);
}
</script>
</head>
<body>
<select onChange="changeSelect(this)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<p id="p">选择后这里的文字会改变</p>
</body>
</html>