您的位置:程序门 -> java ->



关于如何动态的设定下拉列表的初始值


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


关于如何动态的设定下拉列表的初始值
发表于:2007-09-30 14:46:59 楼主
比如有一下拉列表如下
<select   name="select"     id="select">
            <option> 是 </option>
            <option> 否 </option>
                    </select>
int   temp=0;
if(temp=0)
初始值=“是”
else
初始值=“不是”


谢谢赐教,不胜感激,附上代码最佳
发表于:2007-09-30 15:16:161楼 得分:0
int   temp=0;  
<select   name="select"     id="select"   >  
              <option   (temp==0)?"selected='true'":""> 是   </option   >  
              <option   (temp!=0)?"selected='true'":""> 否   </option   >  
</select   >  


看样子lz很喜欢这种语法哦
发表于:2007-10-02 08:27:222楼 得分:0
谢谢楼答案,可是我在jsp页面这样怎么就得不到预想的结果
<%
  int   temp=0;
%>
<select   name="select"     id="select"     >    
                <option   (temp==0)?"selected=   'true   '":""   > 是     </option     >    
                <option   (temp!=0)?"selected=   'true   '":""   > 否     </option     >    
</select     >    
发表于:2007-10-03 02:04:403楼 得分:0
<%
int   a   =   1;
string   b   =   "";
string   c   =   "";

if   (a   ==   1)   {
b   =   "selected";
}   else   {
c   =   "selected";
}
out.println("b:"   +   b);
%>
<br>
<%
out.print("c:"   +   c);
%>
<br>
b= <%=b%>
<br>
c= <%=c%>
<br>
<select>
<option   <%=b%> >
1
</option>
<option   <%=c%> >
2
</option>
</select>
我执行了   可以用的用a来设置初始选项
发表于:2007-10-18 17:19:514楼 得分:0
html code
<% int temp=0; % > <select name="select" id="select"> <option <%if(temp==0){ %>selected<%} %>>是 </option> <option <%if(temp!=0){ %>selected<%} %>>否 </option> </select>


快速检索

最新资讯
热门点击