如果复选框被选中,则移除类

Remove class if checkbox is checked

本文关键字:复选框 如果      更新时间:2023-09-26

我希望onload<span><checkbox>类为空白:

<span id="checkboxx_<?php  echo $nrs['id'];   ?>" class="highlight" > 
   <input type="checkbox" class="checkboxx" id="checkboxx_<?php  echo $nrs['id'];   ?>" style="padding: 0px; margin: 2px;"   <?php echo $value == 1 ? 'checked="checked"' : ''?>>                       
</span>

i have try this

<?php
if($value==1)
{
?>
  <script>
    if (this.checked) {
      document.getElementById("checkboxx_<?php  echo $nrs['id'];   ?>").className = "";
    }
  </script>
<?php
} else {
?>
   <script>$j("#"+pos).addClass("highlight");</script>
<?php
}

document.getElementById("MyElement").className =
document.getElementById("MyElement").className.replace(/(?:^|'s)MyClass(?!'S)/ , '')

实际上你有重复的id在你的代码checkboxx_<?php echo $nrs['id']; ?>跨度和复选框,而且这段代码是错误的,不能工作

<script>if (this.checked) {
            document.getElementById("checkboxx_<?php  echo $nrs['id'];   ?>").className = "";
            }
        </script>

我认为这样使用SMTH会更好:

<span class="<?php echo ($value !== 1 ? 'highlight' : '') ?>" > 
   <input type="checkbox" class="checkboxx" style="padding: 0px; margin: 2px;"   <?php echo $value == 1 ? 'checked="checked"' : ''?>>                       
</span>