0
如何获取并设置jqxSwitchButton值? 我使用此代码来创建一个开关按钮,并且想要获得按钮值。但它不起作用。jqxSwitchButton如何在jquery中获取值?
<meta charset="UTF-8">
<title>SwitchButton</title>
<link rel="stylesheet" href="style/style_edit.css" type="text/css">
<link rel="stylesheet" href="js/jquery-ui-1.11.4.custom/jquery-ui.css">
<link rel="stylesheet" href="js/jquery-ui-1.11.4.custom/external/jqwidgets/styles/jqx.base.css" type="text/css"/>
<link rel="stylesheet" href="js/jquery-ui-1.11.4.custom/external/jqwidgets/styles/jqx.classic.css" type="text/css"/>
<script type="text/javascript" src="js/jquery-ui-1.11.4.custom/external/jquery/jquery-2.1.4.min.js"></script>
<script src="js/jquery-ui-1.11.4.custom/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.11.4.custom/external/jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.11.4.custom/external/jqwidgets/jqxswitchbutton.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.11.4.custom/external/jqwidgets/jqxcheckbox.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#jqxSwitchButton').jqxSwitchButton({checked: true});
// Get the value.
var value = $("#jqxSwitchButton").jqxSwitchButton('val',true);
var value2 = $("#jqxSwitchButton").val();
console.log(value);
console.log(value2);
// Set value.
$("#jqxSwitchButton").jqxSwitchButton('val', true);
// Set value using jQuery's val().
$("#jqxSwitchButton").val(true);
});
</script>
HTML:
<div class="switch_options">
<div id="jqxSwitchButton" value="A"></div>
</div>
它返回两个布尔 “真”,如DOC说: 参数类型 值(可选)布尔 返回值 布尔 我怎样才能获得的价值“一个”? 表示返回String,然后设置该值。 谢谢!