Javascript JQuery在下拉列表中选择所有值,复选框不起作用
我正在使用Flask作为应用程序的框架。我有两个带有复选框的下拉列表,其中选择了id节点,并将填充从数据库中获取的值。第二个列表有静态名称。在页面加载时,我必须选择两个列表中的所有复选框。第一个下拉选择节点工作正常。但第二个下拉列表不是选择任何复选框。我试过这个密码。纠正我哪里错了 HTML JavascriptJavascript JQuery在下拉列表中选择所有值,复选框不起作用,javascript,jquery,ajax,twitter-bootstrap,flask,Javascript,Jquery,Ajax,Twitter Bootstrap,Flask,我正在使用Flask作为应用程序的框架。我有两个带有复选框的下拉列表,其中选择了id节点,并将填充从数据库中获取的值。第二个列表有静态名称。在页面加载时,我必须选择两个列表中的所有复选框。第一个下拉选择节点工作正常。但第二个下拉列表不是选择任何复选框。我试过这个密码。纠正我哪里错了 HTML Javascript 看起来您忘记查询filter select的实际选项了 更改此行: $('#filter-select').prop('selected', true); 致: 复制+粘贴的副作用…
看起来您忘记查询filter select的实际选项了 更改此行:
$('#filter-select').prop('selected', true);
致:
复制+粘贴的副作用…:D非常感谢伙计:太好了。你能检查一下复选标记吗?这样我给你正确答案就可以得分了。
<script type="text/javascript">
$('#nodes-select').change(function(){
console.log("Atleast nodes...");
if($("#nodes-select option[value='-1']").is(':selected'))
{
console.log("node...");
$('#nodes-select option').prop('selected', true);
$("#nodes-select option[value='-1']").prop('selected', false);
}
$('#nodes-select').multiselect('refresh');
});
$('#filter-select').change(function(){
console.log("Atleast filter...");
if($("#filter-select option[value='-1']").is(':selected'))
{
console.log("filter ...");
$('#filter-select option').prop('selected', true);
$("#filter-select option[value='-1']").prop('selected', false);
}
$('#filter-select').multiselect('refresh');
});
function onLoading()
{
alert("Page Loaded");
$.get("/nodes",function(data,status)
{
var tmp = data.output;
console.log("**"+tmp);
$('#nodes-select').append($('<option>', {
value: -1,
text : "All"
}));
for(var i =0;i<tmp.length;i++)
{
console.log(tmp[i]);
$('#nodes-select').append($('<option>', {
value: i,
text : tmp[i]
}));
}
$('#nodes-select').multiselect('rebuild');
$('#nodes-select option').prop('selected', true);
$("#nodes-select option[value='-1']").prop('selected', false);
$('#nodes-select').multiselect('refresh');
$('#filter-select').append($('<option>', {
value: -1,
text : "All"
}));
console.log("&&") ;
var temp = ["MAC","SUBLBL","VRF","IFHNDL","COMP_ID","V4_ADDR","V6_ADDR"];
for(var i =0;i<temp.length;i++)
{
console.log(temp[i]);
$('#filter-select').append($('<option>', {
value: i,
text : temp[i]
}));
}
$('#filter-select').multiselect('rebuild');
$('#filter-select').prop('selected', true);
$("#filter-select option[value='-1']").prop('selected', false);
$('#filter-select').multiselect('refresh');
});
}
</script>
$('#filter-select').prop('selected', true);
$('#filter-select option').prop('selected', true);