Javascript 如何使用jquery获取jquery盆景树的选定值?
我正在尝试从使用jquery盆景(链接:)创建的树结构中获取所选(选中)值 我的代码:Javascript 如何使用jquery获取jquery盆景树的选定值?,javascript,jquery,Javascript,Jquery,我正在尝试从使用jquery盆景(链接:)创建的树结构中获取所选(选中)值 我的代码: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <link rel='stylesheet' type='text/css' href='http://bgagenom
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel='stylesheet' type='text/css' href='http://bgagenomics.iicb.res.in/bga/arup/js/assets/svg-icons.css' />
<link rel='stylesheet' type='text/css' href='http://bgagenomics.iicb.res.in/bga/arup/js/jquery.bonsai.css' />
<script src='http://bgagenomics.iicb.res.in/bga/arup/js/jquery.bonsai.js'></script>
<script src='http://bgagenomics.iicb.res.in/bga/arup/js/jquery.qubit.js'> </script>
<script>
jQuery(function() {
$('#auto-checkboxes').bonsai({
expandAll: false,
checkboxes: true, // qbit plung helper
createInputs: 'checkbox' // enebles auto click data-checked
});
});
$(document).ready(function(){
$("#val").click(function()
{
alert("hello"); //need help here
});
});
</script>
</head>
<body>
<div>
<ol id='auto-checkboxes' data-name='foo'>
<li data-value='0'>All
<ol>
<li data-value='1'>One</li>
<li data-value='2' data-id='2'>
Two
<ol>
<li data-name='baz' data-value='3'>
Three
<ol>
<li data-name='baz' data-value='4'>Four</li>
</ol>
</li>
<li data-value='5'>Five</li>
</ol>
</li>
</ol>
</li>
</ol>
</div>
<br>
<input id ="val" type="image" value = "Result" />
<body>
</html>
jQuery(函数(){
$(“#自动复选框”)。盆景({
全部:错,
复选框:true,//qbit-plung-helper
createInputs:'复选框'//Enables自动单击数据已选中
});
});
$(文档).ready(函数(){
$(“#val”)。单击(函数()
{
提醒(“你好”);//需要帮助吗
});
});
全部
一
两个
三
四
五
上面的代码将创建树结构,如
我希望在单击结果时获得选中值
解决上述问题的任何帮助或建议都将非常有用。您可以通过循环查找选定复选框来获取所有选定复选框的值,如下所示:
var yourArray = [];//global variable
$(document).ready(function(){
$("#val").click(function() {
yourArray = [];//unset previous values
$("input:checkbox[name=yourCheckboxName]:checked").each(function(){
yourArray.push($(this).val());
});
});
});