jQuery选择器用于具有空值属性的选择元素吗?

编程入门 行业动态 更新时间:2024-10-27 00:33:40
本文介绍了jQuery选择器用于具有空值属性的选择元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用下面的选择器来获取所有预先填充有值的表单输入.

I'm using the below selector to get all the form inputs that are pre-populated with a value.

$('input[value!=""]');

这很好用,所以我认为我可以使用以下选择器将相同的逻辑应用于选择元素,尽管它似乎是在Chrome中选择所有选择元素.

This works great and so I thought I could apply the same logic to my select elements using the following selector, though it seems to be selecting all the select elements in Chrome.

$('select[value!=""]');

下面是表单上两种选择的示例:

Below is an example of two types of selects on the form:

<select name="phone2_type" id="phone2_type"> <option value="">Select one:</option> <option value="HOME">Home</option> <option value="CELL">Cell</option> <option value="BUSN">Business</option> </select> <select name="state" id="state"> <option value="">Select one:</option> <option value="XX">Outside USA/Canada</option> <option value="AL" selected="selected">Alabama</option> <option value="AK">Alaska</option> ... </select>

我想选择第二个选择,因为它具有已经使用select ="selected"

I'd like to select the second select since it has a value selected already with the select="selected"

推荐答案

$('select').has('option[selected="selected"]')

将获得选择元素. jsFiddle示例 .

will get the select element. jsFiddle example.

更多推荐

jQuery选择器用于具有空值属性的选择元素吗?

本文发布于:2023-11-05 19:43:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561672.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   元素   选择器   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!