[問題] 怎麼修改option的text
我有一個需求需要 讓 <select> 如果沒有選擇的時候
將裡面的option 裡面的text只顯示前兩個字
當該select 被選擇到的時候,又會恢復原來的字元
然後離開select 的時候,又只顯示前兩個字
我目前是這樣寫
$('option').each(function(){ //一開始載入的時候,把原來的字元存到old_text
var old_text = $(this).text();
$(this).attr('old_text',old_text);
$(this).text(old_text.substring(0,2));
});
$('select').click(function(){ //當按下select,還原字元
$(this).children('option').each(function(){
//$(this).attr('old_text',old_text);
$(this).text($(this).attr('old_text'));
});
});
$('select').change(function(){
$(this).children('option').each(function(){
$(this).text($(this).attr('old_text').substring(0,2));
});
});
$('select').blur(function(){//離開的時候,又再變成兩個字
$(this).children('option').each(function(){
$(this).text($(this).attr('old_text').substring(0,2));
});
});
問題來了,當我選擇了某一個選項之後,並不會馬上 做blur或change
一定得我要手動點網頁其他地方,才會變成兩個字
請問該怎麼改才好
謝謝回覆
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 42.75.115.37
推
12/19 21:44, , 1F
12/19 21:44, 1F
→
12/19 21:45, , 2F
12/19 21:45, 2F
推
12/19 21:49, , 3F
12/19 21:49, 3F
→
12/20 08:21, , 4F
12/20 08:21, 4F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章
7
20