目标是在检查后从输入复选框执行href
复选框输入
<input type="checkbox" value="{{$todo -> id}}" name="{{$todo -> ToDoName}}">
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;
}
});
答案 0 :(得分:0)
创建一个新的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>
解释:
- 您没有为复选框类命名
- 每次选中复选框并取消选中时都会触发更改
- 要获取已检查和未选中的值,您需要获取this.checked(这是指复选框元素,因为我们正在修改此元素的更改事件)