Javascript 将选中的项目推到列表顶部

Javascript 将选中的项目推到列表顶部,javascript,html,jquery,Javascript,Html,Jquery,我有一个带有动态列表项的复选框。我想在“加载列表”中将选中的项推到列表顶部 我尝试了以下代码段中的操作。我尝试更改选中项的颜色。颜色已更改,但未将该项推到列表顶部 $document.readyfunction{ $input[name='geo[]'].eachfunction{ 如果$this.is:已选中{ $this.propchecked,true; $this.parent'li'.css'background-color','3875D7'; $this.parent'li'。在

我有一个带有动态列表项的复选框。我想在“加载列表”中将选中的项推到列表顶部

我尝试了以下代码段中的操作。我尝试更改选中项的颜色。颜色已更改,但未将该项推到列表顶部

$document.readyfunction{ $input[name='geo[]'].eachfunction{ 如果$this.is:已选中{ $this.propchecked,true; $this.parent'li'.css'background-color','3875D7'; $this.parent'li'。在$this前面加上前缀; } }; }; 美国东部 美国西部 NSU 您可以首先作为li的父项访问ul标签,然后将列表项li前置到ul列表中

$document.readyfunction{ $input[name='geo[]'].eachfunction{ 如果$this.is:已选中{ $this.parent'li'。css'background-color','3875D7'; 让item=$this.parent'li'; let list=$item.parent'ul'; $list.prependitem; } }; }; 美国东部 美国西部 NSU 您可以首先作为li的父项访问ul标签,然后将列表项li前置到ul列表中

$document.readyfunction{ $input[name='geo[]'].eachfunction{ 如果$this.is:已选中{ $this.parent'li'。css'background-color','3875D7'; 让item=$this.parent'li'; let list=$item.parent'ul'; $list.prependitem; } }; }; 美国东部 美国西部 NSU $document.readyfunction{ $input[name='geo[]'].eachfunction{ 如果$this.is:已选中{ $this.propchecked,true; $this.parent'li'.css'background-color','3875D7'; $this.parents'ul'。在$this.parents'li'前面加上前缀; } }; }; 美国东部 美国西部 NSU $document.readyfunction{ $input[name='geo[]'].eachfunction{ 如果$this.is:已选中{ $this.propchecked,true; $this.parent'li'.css'background-color','3875D7'; $this.parents'ul'。在$this.parents'li'前面加上前缀; } }; }; 美国东部 美国西部 NSU
你好,我希望这能进一步帮助你,只是实现了列表,而不是你想要的颜色

编辑:添加颜色

风险值列表=$ul; var unorderedList=list.children; list.onclick,:复选框,函数{ var i=document.createDocumentFragment; var checked=document.createDocumentFragment; var unchecked=document.createDocumentFragment; 对于i=0;i你好,我希望这能进一步帮助你,只是实现了列表,而不是你想要的颜色

编辑:添加颜色

风险值列表=$ul; var unorderedList=list.children; list.onclick,:复选框,函数{ var i=document.createDocumentFragment; var checked=document.createDocumentFragment; var unchecked=document.createDocumentFragment; 对于i=0;iphp标记是否相关?是否希望它在选中其他复选框时也动态更改?php标记是否相关?是否希望它在选中其他复选框时也动态更改?