Some question with Jquery string handling

本帖最後由 luckiejacky 於 2015-2-11 20:57 編輯
  1. $(document).on('change','#followupPersonID',function(){                                                                
  2.         var selectedValue = $('#followupPersonID').val();  
  3.         $( "#followupPersonID option:selected" ).removeAttr("selected");
  4.         $( '"#followupPersonID option[value=' + selectedValue + '])"'.attr("selected","selected");  
  5. });
複製代碼


This statement has some problem, but how do I fix it?
Thanks

本帖最後由 KinChungE 於 2015-2-11 22:30 編輯

$( '"#followupPersonID option[value=' + selectedValue + '])"'.attr("selected","selected");  
改為
$( '#followupPersonID option[value=' + selectedValue + '])'.attr("selected","selected");  

selector無需要專登加double quote

TOP

回覆 2# KinChungE


    改為
$( '#followupPersonID option[value=' + selectedValue + ']').attr("selected","selected");

TOP

回覆  KinChungE


    改為
$( '#followupPersonID option[value=' + selectedValue + ']').attr("select ...
gamezz 發表於 2015-2-12 00:02


係喎, 睇漏左添

TOP

比較建議改為咁
$( "#followupPersonID option[value=' + selectedValue + ']").prop("selected","selected");

TOP

回覆 5# wongfung


attr  其實同 prop 有咩分別 ?
我一路都用attr

TOP

回覆  wongfung


attr  其實同 prop 有咩分別 ?
我一路都用attr
gamezz 發表於 2015-2-12 23:16


http://api.jquery.com/prop/
btw 應該喺Selected true先啱

TOP