2017-08-19 11 views
-1

jqueryのdom要素を置き換えるにはどうすればいいですか?jqueryのDom要素を置き換えるにはどうすればいいですか?

私はreplaceWith機能を試してみましたが、どのような私が欲しいの選択ボックスあなたはjQueryので.ATTR使用することができます

$('select[name="role_id"]').on('change',function(){ 
    if ($(this).val() == 3){ 
       // I want to replace the role_id name into product_id 

      } 
    } 
+0

「私が望むものは何ですか」 - 何ですか? –

+0

選択フィールドの値を3に変更した後role_idから他のName_idに名前を変更したい – aibazzs

+1

どのようにhtmlのように見えますか? – Vivian

答えて

0

Try .attr

$('select[name="role_id"]').change(function(){ 
    if ($(this).val() == 3){ 
     $(this).attr('name', 'product_id'); 
    } 
}); 
0

で変更した後です。

$('select[name="role_id"]').on('change',function(){ 
if ($(this).val() == 3){ 
      $(this).attr('name','product_id') 

     } 
} 
関連する問題