2016-11-28 7 views
0

テキストをスパンに変更する必要があります。テキストを<span>(jqueryコマンド)に変更

私はドロップダウンメニューを持っているため、これはjQueryセレクタオプションを使用していますが、これはオプションからのみ選択してテキストを変更しません。

"seleziona"を他のテキストに変更する必要があります。

+1

(* * [mcve] *)コード自体を投稿しないでください。また、「* jQueryセレクタオプション*」は何を使っていますか?どこで立ち往生しましたか?あなたの試みは何が間違っていましたか?コードが何を期待していましたか?代わりに何をしましたか? –

+0

私はこれを使用します:var theText = ""; $ {"オプション"} { if($(this).text()== theText){ $(this).attr( 'selected'、 'selected'); } }); –

答えて

1
  1. あなたはそれから

1.

$("#span1").on('change',function(){ 
//Do calculation and change value of other span here 
$("#span2").text('calculated value');}); 

2.

$("#span1").text('test').trigger('change'); 
をトリガー変更イベント
  • を行うことができます
  • 0

    Srebnywilkunが投稿した回答は正しいです。この回答は短い記法だけを提供します。

    $("#span1").on('change',function(){ 
        $("#span2").text('calculated value'); 
    }).change(); // defining this at the end of the function would automatically trigger the change event after the event is registered. 
    
    関連する問題