wma*_*dox 4 javascript checkbox jquery jquery-ui
我正在尝试以编程方式检查/取消选中jquery-ui checkboxradio小部件(即不使用鼠标)。我尝试过各种各样的事情,但没有快乐。要重现该问题,请选择一个仅包含jquery和jquery-uiscript 标签的空白 html 页面,然后动态创建小部件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blank</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
页面加载后,我点击F12打开开发工具并输入以下命令以获得最小jquery-ui复选框:
$container = $("<div>")
$container.append($("<label for='chkbox'>"))
$container.append($("<input type='checkbox' id='chkbox'>"))
$container.appendTo('body')
$('#chkbox').checkboxradio()
Run Code Online (Sandbox Code Playgroud)
默认情况下该复选框未选中。让我们尝试检查一下:
$('#chkbox').attr('checked', true) // nope
$('#chkbox').checkboxradio('refresh') // nope
$('#chkbox').attr('checked', false)
$('#chkbox').prop('checked', true) // nope
$('#chkbox').prop('checked', false)
$('#chkbox').addClass('ui-checkboxradio-checked') // not this either
$('#chkbox').removeClass('ui-checkboxradio-checked')
$('#chkbox').checkboxradio('option', 'classes.ui-checkboxradio-checked', true) // does nothing
$('#chkbox').checkboxradio('option', 'ui-checkboxradio-checked', true) // does nothing
$('#chkbox').checkboxradio('option', 'classes.ui-checkboxradio.ui-checkboxradio-checked', true) // and again, nothing...
Run Code Online (Sandbox Code Playgroud)
这很令人恼火。有谁能解决这个看似简单的问题吗?
我希望它应该对你有帮助谢谢。
$container = $("<div>")
$container.append($("<label for='chkbox'>"))
$container.append($("<input type='checkbox' id='chkbox' >"))
$container.appendTo("body")
$("#chkbox").checkboxradio();
$("#chkbox").prop("checked",true).checkboxradio("refresh")Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blank</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7650 次 |
| 最近记录: |