首页 > 编程知识 正文

html复选按钮标签,html添加单选框

时间:2023-05-03 15:19:44 阅读:263625 作者:2081

html如何实现勾选复选框实现出现和隐藏

<div class="yaosu1">
    <p><input type="checkbox" checked="" name="category" value="锅炉" οnclick="my_func('锅炉')">锅炉 </p>
    <p><input type="checkbox" checked="" name="category" value="电梯" οnclick="my_func('电梯')">电梯</p>
    <p><input type="checkbox" checked="" name="category" value="压力管道" οnclick="my_func('压力管道')">压力管道</p>
    <p><input type="checkbox" checked="" name="category" value="客运索道" οnclick="my_func('客运索道')">客运索道</p>
    </div>

==

Html中使用自定义图片来实现checkbox显示

如果需要使用图片来实现checkbox的使用,可以使用来实现,实现原理是将label表签代替checkbox的显示,将checkbox的display设置为none,在label标签中使用要显示的图片img,再使用js函数去控制图片的选中与否的切换。

    <label  for="agree" >           
        <img  class="checkbox" alt="选中" src="../img/checked.png" id="checkimg" οnclick="checkclick();">
     </label>   
     <input type="checkbox"  style="display:none" id="agree" checked="checked">
     <script>
         function checkclick(){
            var checkimg = document.getElementById("checkimg");
            if($("#agree").is(':checked') ){
                $("#agree").attr("checked","unchecked");
                checkimg.src="../img/unchecked.png";
                checkimg.alt="未选";
            } else{
                $("#agree").attr("checked","checked");
                checkimg.src="../img/checked.png";
                checkimg.alt="选中";
            }
        }
    </script>

==

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。