2016-11-28 23 views
0

我需要將文本更改爲跨度。使用jquery命令將文本更改爲<span>

我正在尋找這個,因爲我有一個下拉菜單,我使用jQuery選擇器選項,但這不會更改文本,只能從選項中進行選擇。

我需要改變「seleziona」與其他文本。

+1

你的代碼的請不要張貼照片,發佈( 「* [MCVE] *」),代碼本身。另外,你使用了什麼「* jQuery選擇器選項*」?你卡在哪裏?你的嘗試出了什麼問題?你期望代碼做什麼,它做了什麼? –

+0

我使用這個:var theText =「」; ((#) $(「#option」)。each(function(){ if($(this).text()== theText){ $(this).attr('selected','selected'); } }); –

回答

1
  1. 你可以做一個改變事件
  2. 然後觸發它

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. 
相關問題