JQ获取option的name和data-id

来源:https://zhidao.baidu.com/question/692142321436883524.html

用jq的attr()函数,如:

HTML:

<select>
    <option name="aa" data-id="01"></option>
     <option name="bb" data-id="02" selected="selected"></option>
      <option name="cc" data-id="03"></option>
</select>

 

 

JQ:

$(document).ready(function(){
    var a = $("select option:selected").attr("name");
    var b = $("select option:selected").attr("data-id");
    alert(a + "\n" + b);
});

 

猜你喜欢

转载自www.cnblogs.com/laijinquan/p/8952078.html
0条评论
添加一条新回复