[英]jQuery sortable() - How to check if two <li> elements are next to each other by class?
I am developing a display builder for outdoor power equipment dealers, in which they can add, remove, and rearrange product display sections as they see fit. 我正在为户外电力设备经销商开发一个显示器制造商,他们可以根据需要添加,移除和重新安排产品展示部分。 I used a
<ul>
with JQuery-ui sortable()
to do this: 我使用带有JQuery-ui
sortable()
的<ul>
来执行此操作:
This is the sortable <ul>
, called #display-sections
这是可排序的
<ul>
,称为#display-sections
<ul id="display-sections">
</ul>
When a button is pressed to add a section(blower, chainsaw, hedge trimmer, trimmer, accessories, PAS, cordless), a <li>
is appended with the appropriate class. 当按下按钮添加一个部分(鼓风机,电锯,绿篱机,修剪器,配件,PAS,无线)时,
<li>
附加相应的类。
For example, if I click on the button to add a blower section, a <li>
is added with the class echo-blower-section
: 例如,如果我单击按钮添加鼓风机部分,则会添加类似
echo-blower-section
的<li>
:
function addBlowerSection() {
$("#display-sections").append('<li class = "echo-blower-section"><img src = "echo-blower-section.jpg" width = "145" height = "288"></li>');
}
There are two display sections, the PAS and Cordless Sections, classes echo-pas-section
and echo-cordless-section
that I want to check if they are NOT next to each other, since it is recommended that these two sections stay together in a showroom. 有两个显示部分,PAS和无绳部分,类
echo-pas-section
和echo-cordless-section
,我想检查它们是否彼此不相邻,因为建议这两个部分保持在一起陈列室。
How would I do this using JavaScript/JQuery? 我如何使用JavaScript / JQuery做到这一点? I would like to present an alert if the
echo-pas-section
and echo-cordless-section
list items are NOT next to each other in the <ul>
如果
echo-pas-section
和echo-cordless-section
列表项在<ul>
彼此不相邻,我想提示一个警告
I've not tested, but I think something like this should do the trick :-) 我没有测试过,但我觉得这样的事情应该可以解决问题:-)
var cordless = $("#display-sections li.echo-cordless-section");
var pas = $("#display-sections li.echo-pas-section");
if(cordless.length && pas.length && !cordless.next('li').is(pas) && !pas.next('li').is(cordless)){
alert('!');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.