整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

jq实现全选,全取消,反选

jq实现全选,全取消,反选

lt;!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<script type="text/javascript" src="jquery.min.js"></script>

</head>

<body>

<input type="checkbox" id="checkbox1"><label for="checkbox1">库里</label><br>

<input type="checkbox" id="checkbox2"><label for="checkbox2">科比</label><br>

<input type="checkbox" id="checkbox3"><label for="checkbox3">麦迪</label><br>

<input type="checkbox" id="checkbox4"><label for="checkbox4">邓肯</label><br>

<input type="checkbox" id="checkbox5"><label for="checkbox5">奥尼尔</label><br><br>

<button>全选</button><button>全不选</button><button>反选</button>

</body>

</html>

<script type="text/javascript">

$(function(){

//匹配第一个button

$(':button:eq(0)').click(function(){

//全部选中 checked=true,在前台就是表示选中

$(':checkbox').attr('checked',true);

});

//匹配第二个button

$(':button:eq(1)').click(function(){

//全部取消 checked=false,在前台就是表示未选中

$(':checkbox').attr('checked',false);

});

//匹配第三个button

$(':button:eq(2)').click(function(){

//查找每一个复选框,然后取相反

$(':checkbox').each(function(){

$(this).attr('checked',!$(this).attr('checked'));

});

});

})

</script>

、CSS方法

.disabled { pointer-events: none; }

二、jQuery方法

方法一

$(this).click(function (event) {
    event.preventDefault();
}

方法二

$('a').live('click', function(event) {
    alert("抱歉,已停用!");
    event.preventDefault();
});

注:此方法中的live亦可以为on, bind等方法

方法三

$('.disableCss').removeAttr('onclick'); //去掉标签中的onclick事件

通过removeAttr方法来控制html标签的属性已达到启用或禁用事件。另, 使用这种方式也可以控制其他事件或其他效果。

方法四

$('#button').attr('disabled',"true");//添加disabled属性
$('#button').removeAttr("disabled"); //移除disabled属性

注:和方法三是一样的, 不过disabled属性一般用在类型为button或submit的input上

s vue jq消除某个元素的click点击事件

原生js:

//页面
<div style="margin-top:20px;">
    <button onclick="clickMethod()" id="btn">点我</button>
    <button onclick="clearMethod()" >清除方法</button>
    <button onclick="clearMethod2()" id="btn2">jq清除方法</button>
</div>
  • 可以直接赋值为空,但是清除后,再次点击,控制台会报错
  • 直接修改方法,虽然没有报错,但是也没有清除,当然也要以return false
  • 直接删除onclick,这个最完美
//原生js清除单击事件
    function clickMethod(){
        alert('我被点击了')
    }
    function clearMethod(){
        // clickMethod=""  //会报错
        // clickMethod=function(){
        //     console.log("我被修改了")
        // }
        console.log(document.getElementById('btn'))
        document.getElementById('btn').onclick=""  //不会报错

    }

jquery:直接了当

 //jq清除单击事件
    function clearMethod2(){
        $('#btn').removeAttr('onclick')
    }

vue

vue没有提供删除事件的方法,但是可以通过赋值的方式:

还有一种方式,通过增加一个变量的方式来完成不让元素的事件触发