点击checkbox,触发事件

时间选择:
起始时间:<input  type="text" value="2016-03-21 12:24:10" id="starttime"  size="" class="m-wrap wid200 " onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
结束时间:<input type="text" value="2017-03-21 12:24:10" size="" class="m-wrap wid200 " id="startime1" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
checkbox复选框: <input type="checkbox" value="" style="opacity: 0;" id="callever" name="callever">
<script>
//        区域报警设置的是否每天报警的时间不可选择的js        
$(function(){
    $("#callever").change(function(){
        if($("#callever").prop("checked")){           //prop()函数用于设置或返回当前jQuery对象所匹配的元素的属性值,复选框被选中时
             $("#starttime").attr('readonly','readonly');  //时间input文本添加属性值 
            document.getElementById("starttime").style.color='rgb(173, 173, 173)';
             document.getElementById("starttime").onclick=function(){};
            $("#startime1").attr('readonly','readonly');
            document.getElementById("startime1").style.color='rgb(173, 173, 173)';
             document.getElementById("startime1").onclick=function(){};
                
        }else{
            document.getElementById("starttime").style.color='rgb(63, 63, 63)';
            document.getElementById("startime1").style.color='rgb(63, 63, 63)';
             $("#starttime").removeAttr('readonly','');
             $("#startime1").removeAttr('readonly','');
              document.getElementById("starttime").onclick=function(){laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})};
               document.getElementById("startime1").onclick=function(){laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})};
        }
    })
})


    </script>
原文地址:https://www.cnblogs.com/dazhangli/p/5336208.html