2016-06-18 8 views
0

以下は私のhtml Dom.私は選択オプションのデータ属性をフェッチしたいです。私の次のjQueryが動作していないdata-brand-idフェッチするためにjqueryで選択されたオプションのデータ属性を取得できません

<table class="fanpage-table"> 
    <tbody> 
     <tr> 
      <td>Blog System...</td> 
      <td>History......</td> 
      <td> 
       <select name="brand_dropdown"> 
        <option data-brand-id="xxxthisxxxxxxx">PKB</option> 
        <option data-brand-id="xxxthisxxxxxxx">QKJ</option> 
       </select> 
      </td> 
      <td><i class="fa fa-check-square-o save-fan-page" data-fanpage-id="xxxxxxxxxx"></i></td> 
     </tr>  
    </tbody> 
</table> 

$(".save-fan-page").on("click",function() 
{ 
    $(this).closest("tr").find("select[name='brand_dropdown']option:selected").data("brand-id"); 
} 

答えて

2
$(".save-fan-page").on("click",function() { 
    $(this).closest("tr").find("select[name='brand_dropdown'] option:selected").data("brand-id"); 
} 

お知らせselectoption:selected のための属性セレクタの間スペースは、私は問題が何であるかと思います。あなたの場合は、がありませんです。

1

space

select[name='brand_dropdown']間と option:selectedを与えるこの

$(this).closest("tr").find("select[name='brand_dropdown'] option:selected").data("brand-id"); 

をお試しください

関連する問題