是否可以禁止对复选框执行某些操作?例如,我想留下$('#post-id')和$('#activation')复选框总是被选中,没有任何可能取消选中它们?
$("#activation").attr("checked", true);
$("#post-id").attr("checked", true);
我可以在这里找到我的例子: https://jsfiddle.net/9LzLm9hx/1/
答案 0 :(得分:3)
你可以这样使用
$( '#common' ).on('click', function () {
$( '.common-inputs [type="checkbox"]:not([disabled])' ).prop('checked', this.checked);
});
//checkbox
$("#activation").attr("checked", true);
$("#post-id").attr("checked", true);
$("#activation").attr("disabled", true);
$("#post-id").attr("disabled", true);
答案 1 :(得分:0)
您只需将 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Home</title>
<script type="text/javascript"
src="${request.getContextPath()}/web/easyui/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#course").change(function(){
alert(1);
});
});
</script>
</head>
<body>
<select id="course">
<option value="1">option a</option>
<option value="2">option b</option>
</select>
</body>
</html>
添加到相关复选框即可。
然后,它们具有默认值,但不再可编辑。
这些是有问题的变化:
disabled
这将是您更新的jsfiddle: https://jsfiddle.net/9LzLm9hx/2/
享受:)
答案 2 :(得分:0)
您可以在选中true后使用此代码段。
<script>
function HideandDisabled(){
$("#activation").attr("checked", true);
document.getElementById("activation").disabled=true;
$("#post-id").attr("checked", true);
document.getElementById("post-id").disabled=true;
}
</script>