要使用jquery更改的Struts2复选框标签

要使用jquery更改的Struts2复选框标签,jquery,struts2,jsp-tags,Jquery,Struts2,Jsp Tags,我正在使用jquery更改复选框的标签 use strict'; $("#chId").click(function () { if (this.checked) { $('#divId').html("Checked"); } else{ $('#divId').html("Un-Checked"); } }); 如果我以常规html样式指定复选框,它可以正常工作 <input type="checkbox" id="chI

我正在使用jquery更改复选框的标签

use strict';
$("#chId").click(function () {
   if (this.checked) {
         $('#divId').html("Checked");
   }
   else{
         $('#divId').html("Un-Checked");
   }

});
如果我以常规html样式指定复选框,它可以正常工作

<input type="checkbox" id="chId"/> 
<div id='divId'>Checked</div>
但是,如果我有多个复选框,所有标签都将具有相同的类“.label”,我不知道如何通过复选框不同时更改不同的文本 基本上,我想 1) 有5个标签都有不同的类别“label1”。。。“label5”或 2) 在每个标签上都有id以便。。。或 3) 能够在jquery选择器中使用“for”属性吗? 我认为(3)是我最好的选择,但我不知道怎么做。
有人能帮忙吗?
谢谢

将class和id属性赋予复选框,并用于获取标签元素,其中的
属性等于复选框id

<script type="text/javascript">
  $(function () {
    $(".checkb").click(function () {
      if(this.checked) {
        $("label[for="+this.id+"]").html("Checked");
      }else {
        $("label[for="+this.id+"]").html("Un-Checked");
      }
    });
  });
</script>

<s:checkbox cssClass="checkb" id="checkid1" name="check1" label="Un-Checked"/>
<s:checkbox cssClass="checkb" id="checkid2" name="check2" label="Un-Checked"/>

$(函数(){
$(“.checkb”)。单击(函数(){
如果(选中此项){
$(“label[for=“+this.id+”]”)html(“选中”);
}否则{
$(“label[for=“+this.id+”]”)html(“未选中”);
}
});
});
$('.label').html("Checked");
<script type="text/javascript">
  $(function () {
    $(".checkb").click(function () {
      if(this.checked) {
        $("label[for="+this.id+"]").html("Checked");
      }else {
        $("label[for="+this.id+"]").html("Un-Checked");
      }
    });
  });
</script>

<s:checkbox cssClass="checkb" id="checkid1" name="check1" label="Un-Checked"/>
<s:checkbox cssClass="checkb" id="checkid2" name="check2" label="Un-Checked"/>