在使用struts標簽html:checkbox 的時候,如何讓checkbox框默認是選中的,一般情況下都是當Formbean里面該Property的值和標簽上value給定的值相等的時候,生成的jsp頁面上才是選中的。
在Struts中幾種情況可以使標簽初始就是選中的,Formbean里面該Property的值設為 1.on 、2.yes 、3.true 這三種情況都是可以實現默認選中的。
注:如果不選中,最好把Property的設置為"",因為在Action中得到Property是為null值,在不太注意的情況,它是會出現異常。
復制代碼 代碼如下:
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;
}
}
復制代碼 代碼如下:
<html:checkbox property="id">CheckBox</html:checkbox>
新聞熱點
疑難解答