在使用struts標(biāo)簽html:checkbox 的時(shí)候,如何讓checkbox框默認(rèn)是選中的,一般情況下都是當(dāng)Formbean里面該P(yáng)roperty的值和標(biāo)簽上value給定的值相等的時(shí)候,生成的jsp頁面上才是選中的。
在Struts中幾種情況可以使標(biāo)簽初始就是選中的,F(xiàn)ormbean里面該P(yáng)roperty的值設(shè)為 1.on 、2.yes 、3.true 這三種情況都是可以實(shí)現(xiàn)默認(rèn)選中的。
注:如果不選中,最好把Property的設(shè)置為"",因?yàn)樵贏ction中得到Property是為null值,在不太注意的情況,它是會(huì)出現(xiàn)異常。
復(fù)制代碼 代碼如下:
public class CheckBoxForm extends ActionForm {
// private String id = "";
private String id = "on";
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
復(fù)制代碼 代碼如下:
<html:checkbox property="id">CheckBox</html:checkbox>
新聞熱點(diǎn)
疑難解答
圖片精選