当前位置: 代码迷 >> Java Web开发 >> select box的有关问题,当其中一个选项被选上,页面要出现一个textfield
  详细解决方案

select box的有关问题,当其中一个选项被选上,页面要出现一个textfield

热度:211   发布时间:2016-04-17 12:23:24.0
求一个select box的问题,当其中一个选项被选上,页面要出现一个textfield.
这是selectbox的源码:
<td>
<select name="carrierName">
<% String selectedOrderCarrierName = requestFrmObj.getCarrierName(); %>
<option value="Toll Online" <% if(selectedOrderCarrierName.equalsIgnoreCase("Toll Online")){ %> selected <% } %>>Toll Online</option>
<option value="Toll Priority" <% if(selectedOrderCarrierName.equalsIgnoreCase("Toll Priority")){ %> selected <% } %>>Toll Priority</option>
<option value="Australia Post" <% if(selectedOrderCarrierName.equalsIgnoreCase("Australia Post")){ %> selected <% } %>>Australia Post</option>
<option value="Other" <% if(selectedOrderCarrierName.equalsIgnoreCase("Sent")){ %> selected <% } %>>Other</option>
</select>  
</td>

当"other"被选中时,页面中要出现一个textfield,用来写出carriername,然后这个textfield里的carriername要能提交到javabean相对的getCarrierName中.用javascript能实现么?大家给些设计意见可以么?最好是源程序啦!!

------解决方案--------------------
<!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="">
<script>
function show(){
var carrierName=document.getElementById("carrierName");
var b=document.getElementsByTagName("BODY")[0];
for(var i=0;i<carrierName.options.length;i++){
if(carrierName.options[i].value==2){
var text=document.createElement("input");
text.type = "text"; 
text.value=carrierName.options[i].value;
b.appendChild(text);

}
}

}
</script>
</HEAD>

<BODY>
<select id="carrierName" onChange="javaScript:show();">
<option value="1">1</option>
<option value="2">2</option>
</select>
</BODY>
</HTML>
就是个样子而已,希望有帮助
------解决方案--------------------
<td> 
<select name="carrierName"> 
<% String selectedOrderCarrierName = requestFrmObj.getCarrierName(); %> 
<option value="Toll Online" <% if(selectedOrderCarrierName.equalsIgnoreCase("Toll Online")){ %> selected <% } %>>Toll Online </option> 
<option value="Toll Priority" <% if(selectedOrderCarrierName.equalsIgnoreCase("Toll Priority")){ %> selected <% } %>>Toll Priority </option> 
<option value="Australia Post" <% if(selectedOrderCarrierName.equalsIgnoreCase("Australia Post")){ %> selected <% } %>>Australia Post </option> 
<option value="Other" <% if(selectedOrderCarrierName.equalsIgnoreCase("Sent")){ %> selected <% } %>>Other </option> 
</select>
</td> 
<!--让文本框隐藏 -->
<input type="text" value="xxxxx" style="display:none;" id="inp" />
<script type="text/javascript">
//得到select对象
var selects = document.getElementById("carrierName");
//如果默认选择Other 的时候 让文本框显示
if(selects.value == 'Other'){
var inp = document.getElementById("inp");
inp.style.display = "block";
  相关解决方案