JS设置select标签的默认值

普通的HTML select标签在显示的时候总是默认的显示第一个

JSP文件:

< body onload ="checkModel()" >
  
< form action = " <%=request.getContextPath()%>/secretboxInfoAction.do "  method = " post "  name = " ClientForm " >
< tr >
    
< td  class = " td " >< span  class = " font13b " > 型号 : span >
        
< select id = " mod "  style = " width:115pt "  name = " model "  value = ""  onkeydown = " model_prompt_del() " >
            
< option value = "" >------ 请选择 ------             
            
< option value = " 转盘 "   > 转盘
            
< option value = " 密码 "   > 密码
            
< option value = " 金柜 "   > 金柜
        
select >  
    
< span id = " model_prompt "   class = " style1 " >* span >< html : errors property = " model " />
tr >
body >

< script type = " text/javascript " >

function  checkModel() { 
    
if ( " ${secretboxInfo.model} " == " 转盘 " ){ 
        document
. getElementById( " mod " ) . value = " 转盘 "
    } 
else   if ( " ${secretboxInfo.model} " == " 密码 " ){ 
        document
. getElementById( " mod " ) . value = " 密码 "
    } 
else   if ( " ${secretboxInfo.model} " == " 金柜 " ){ 
        document
. getElementById( " mod " ) . value = " 金柜 "
    } 
else {
        document
. getElementById( " mod " ) . value = "" ;
    }


script >

 secretboxiInfo为Action端

SecretboxInfo  secretboxInfo  =  secretboxInfoDAO.getSecretboxInfoByKey(key);
request.setAttribute(
"secretboxInfo",secretboxInfo);

传回的secretboxiInfo类对象。

你可能感兴趣的:(技术类)