Jquery 检查类是否存在于多个元素之一中
如何检查多个 li 元素之一中是否存在类,如果有则调用函数?
嵌套的 和
中有多个
;
列表。我需要的是检查每个 .selectbox ul
内是否是具有关联 .selected
类的许多 li a
元素之一。如果是这样,请将其值传递到
value 属性。这是一个代码:
<div id="selectbox1" class="selectbox">
<input type="hidden" name="selectbox1" />
<ul>
<li><a href="#" name="value01">Option 01</a></li>
<li><a href="#" name="value02">Option 02</a></li>
<li><a href="#" name="value03" class="selected">Option 03</a></li>
<li><a href="#" name="value04">Option 04</a></li>
<li><a href="#" name="value05">Option 05</a></li>
</ul>
</div>
谢谢大家,我选择了最低毫秒响应时间。
How to check if there is a class in one of the many li
elements, if so call a function ?
There is multiple <div class="selectbox"/>
within nested <input type="hidden"/>
and <ul />
list. What i need is to check if inside each .selectbox ul
is one of many li a
element with associated .selected
class. If so, pass it's value into <input type="hidden"/>
value attribute.
Here is a code:
<div id="selectbox1" class="selectbox">
<input type="hidden" name="selectbox1" />
<ul>
<li><a href="#" name="value01">Option 01</a></li>
<li><a href="#" name="value02">Option 02</a></li>
<li><a href="#" name="value03" class="selected">Option 03</a></li>
<li><a href="#" name="value04">Option 04</a></li>
<li><a href="#" name="value05">Option 05</a></li>
</ul>
</div>
Thank you guys to all of you, i choosed with the lowest ms response time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这应该可以做到:
实时示例(出于演示目的,隐藏更改为文本): http://jsfiddle.net/YL4AB/
实例2(显示多个
.selectbox
div):http://jsfiddle.net/ YL4AB/1/This should do it:
Live example (with hidden changed to text for demo purpose): http://jsfiddle.net/YL4AB/
Live example 2 (Showing multiple
.selectbox
div's): http://jsfiddle.net/YL4AB/1/我会通过获取“selectbox”
div
下的所有input
元素的集合,然后查找选定的a
(如果任何)。例如:实例,我将隐藏输入设置为文本输入,以便您可以看到它。单击该按钮来触发上述代码。 (单击链接会更改选定的链接,但不会更新输入 - 因此您可以看到单击按钮时会发生什么。)我还使用 CSS 来突出显示选定的链接。
I'd do it by getting a set of all of the
input
elements under the "selectbox"div
and then finding the selecteda
(if any). E.g.:Live example, I made the hidden input a text input so you could see it. Click the button to fire the above code. (Clicking the links changes which one is selected, but doesn't update the input -- so you can see what happens when you click the button.) I also used CSS to highlight the selected one.
这是一些代码,解释了它的作用:
它非常简单,并且符合大多数其他人所说的内容。希望文档能有所帮助。
Here's some code, explaining what it does:
It's pretty simple, and fits in with what most everyone else has said. Hopefully the documentation will help out a bit.