<select>
<option value="1" >-是</option>
<option selected value="0" >-否-</option>
</select>
<input type="text" style="DISPLAY: none">
当选择是的时候,将出现这个INPUT这代码怎么写?
<option value="1" >-是</option>
<option selected value="0" >-否-</option>
</select>
<input type="text" style="DISPLAY: none">
当选择是的时候,将出现这个INPUT这代码怎么写?
<option value="1" >-是</option>
<option selected value="0" >-否-</option>
</select>
<input type="text" style="DISPLAY: none" id="ipt">
利用这些 ID 操作:var $id = document.getElementById;
$id("sel").onchange = function(){
$id("ipt").style.display = "inine-block";
};
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> test </TITLE>
<script type="text/javascript">
function change(val){
if(val == 1){
document.getElementById("text").style.display = "";
}
}
</script>
</HEAD>
<BODY>
<select onchange="change(this.value);">
<option value="1" >-是</option>
<option selected value="0" >-否-</option>
</select>
<input id="text" type="text" style="DISPLAY: none">
</BODY>
</HTML>
当然你依然可以加上ID之后用jquery(如果你用的习惯就用) document.realy(){
$id("sel").onchange = function(){
$id("ipt").style.display = "inine-block";
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>2011-12-09测试</title>
<script type="text/javascript">
window.onload = function() {
document.getElementById('choice').onchange = test;
};
var test = function() {
if(this.selectedIndex == 0) {
document.getElementsByTagName('input')[0].style.display = '';
} else {
document.getElementsByTagName('input')[0].style.display = 'none';
}
};
</script>
</head><body>
<select id="choice">
<option value="1" >-是</option>
<option selected="selected" value="0" >-否-</option>
</select>
<input type="text" style="DISPLAY: none">
</body>
</html>