我有这个html选择:
<select id="select-filter-item" data-hasqtip="true" title="" aria-describedby="qtip-3">
<optgroup label="Servizi" type="services-group">
<option type="provider">Tutti i trattamenti</option>
<option value="13" type="service">Taglio</option>
<option value="14" type="service">Colore</option>
</optgroup>
</select>如何看到我有第一个选项而没有value属性,我想要检查从select中选择的当前值是否有属性value,如果是的话,得到value号为13或14。如何实现这一点?
我得到的价值就像:
var po = $('#select-filter-item').val();发布于 2015-10-31 16:53:14
您可以使用isNaN()查看该值是否为数值。
$('#select-filter-item').change(function(){
var val = $(this).val();
var isNumber = val !='' && !isNaN(val );
alert(isNumber);
});发布于 2015-10-31 16:35:37
var selected = $("#select-filter-item option:selected"),
val = $(selected).val();
if(val){ //this checks if the value is not falsy (0, undefined, null, "", false)
if(typeof val === "string"){
//do something with your string
} else if(typeof val === "number") {
//do something with your number
}
}
/* You can also use jQuery instead of css selector
to go through a div tree, as far as I know it has better
performance
*/
//var selected = $("#select-filter-item").find("option:selected"); https://stackoverflow.com/questions/33453896
复制相似问题