将心比心,方得人心~

Jquery 获取select选中项 自定义属性的值

周洲 2020-07-21 10:51:48

// html
<select name="fruits" id="fruits">
	<option value="">请选择</option>
	<option data-type=1 value="1">苹果</option>
	<option data-type=0 value="2">香蕉</option>
</select>

// js
//第一种取值
$('#fruits').find("option:selected").attr("data-type")

//第二种取值
//如果你的属性定义的是data-xxx,那么直接
$('#fruits').find("option:selected").data("xxx");
$('#fruits').find("option:selected").data("type")


打赏

『微信打赏』

Tag标签jquery 

我是有底线的