开发者

jQuery get dropdown rel value()

开发者 https://www.devze.com 2023-02-03 02:20 出处:网络
how do i get the dropdown rel=\"30\" value? <select id=\"t_dermal_name\"> <option value=\"1\" rel=\"30\">Between Eyebrows</option>

how do i get the dropdown rel="30" value?

  <select id="t_dermal_name">
     <option value="1" rel="30">Between Eyebrows</option>
       <option value="7" rel="30">Individual Line Softening</option>
       <option value="2" rel="30">Lip Contouring</option>
   </se开发者_Go百科lect>

jquery:

$("#t_dermal_name").change(onSelectChange);

function onSelectChange(){
    var selected = $("#t_dermal_name option:selected");     
    var output = "";
    if(selected.val() != 0){
        output = selected.rel();
    }
    $("#output").html(output);
}


You can use the :selected selector to find the selected option and retrieve its rel value using the attr() method.

Something like this: http://jsfiddle.net/yAQhq/

$("#t_dermal_name").change(onSelectChange);

function onSelectChange(){
    var output = "",
        $this = $(this);

    if($this.val() != 0){
        output = $this.find('option:selected').attr('rel');
    }
    $("#output").html(output);
}


$('select[name="X"] option[selected]').attr('data-xxx') was the only thing that worked for me.


<select name="xx" class="xxx" onchange="_name(this.options[this.selectedIndex].value,this.options[this.selectedIndex].getAttribute('rel'))">
  <option value="x" rel="xy">aa</option>
  <option value="xxx" rel="xyy">bb</option>
</select>


//for javascript
function _name(value,rel) {
alert(value+"-"+rel);
}

good works.


You can use the option:selected

For example, i am using the follow code:

$("#mySelectId").on("change",function(){
   relValue =$("#mySelectId option:selected").attr("rel");
   console.log("You rel value is "+relValue);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消