简体   繁体   English

选中后执行复选框动作

[英]Execute Checkbox action once checked

The objective is to execute href from input checkbox once checked 目的是在选中输入框后执行href

checkbox Input 复选框输入

<input type="checkbox" value="{{$todo -> id}}" name="{{$todo -> ToDoName}}">

js js

/* The todo list plugin */


 $(".todo-list").todolist({
    onCheck: function (ele) {
      window.console.log("The element has been checked");
      return ele;
    },
    onUncheck: function (ele) {
      window.console.log("The element has been unchecked");
      return ele;
    }
  });

Create a new html file, and copy paste the following codes : 创建一个新的html文件,然后复制粘贴以下代码:

<!doctype html>
<html>
    <body>
        <input type="checkbox" class="todo-list" value="True" name="{{$todo -> ToDoName}}">
        <script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
        <script>
            (function(){
                $(".todo-list").change(function(data){
                    var value = this.checked;
                    if (value == true){
                        console.log("The element has been checked");
                    } else {
                        console.log("The element has been unchecked");
                    }
                });
            })();
        </script>
    </body>
</html>

Explaination : 说明:

  • You did not give a name to your checkbox class 您没有为复选框类命名
  • The change is triggered every time checkbox is checked and unchecked 每次选中和取消选中复选框时都会触发更改
  • To get the checked and unchecked value, you need to get this.checked (this refers to the checkbox element, since we're modifying this element's change event) 要获取选中和未选中的值,您需要获取this.checked(这是指checkbox元素,因为我们正在修改该元素的change事件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM