2015-06-10 43 views
0

我有一個something.php將打印dropdownlist的選項,\jquery.load( 「something.php」)都不盡如人意

然後我加載.php文件,

$("#dropdownlist").load("something.php"); 

我加載後時,將顯示輸出,但是當我改變所選擇的值,在調試模式下我DIN不上的dropdownlist選項看見一個selected="selected",我無法設置selectedvaluedropdownlist也與

$("#dropdownlist").val("2"); 

任何人都知道爲什麼會發生這種情況,我該如何解決?

附加代碼

.php --print選項 -

while (isset($StatusArr[$loopCount])) { 
if ($loopCount == 0) { 
    $selected = "selected='true'"; 
} else { 
    $selected = ""; 
} 

echo "<option value='" 
. $StatusArr[$loopCount][0] 
. "' " 
. $selected 
. " >" 
. $StatusArr[$loopCount][1] 
. "</option>"; 

$loopCount ++; 
} 

---撥打.js ----

$('#select').load("../something.php", function (respond, fstatus, xhr) { 
    if (fstatus === "success") { 
     if (status !== "missing") { 
      $('#status').prop("selectedIndex", 3);     
     } 
    } else { 
     alert("Load data " + fstatus + "\n" + xhr.status + " " + xhr.statusText); 
    } 
}); 
+3

所以你想設置下拉列表中的第二個選項使用jQuery選擇?你能展示下拉列表的html代碼是怎麼樣的嗎? – chris97ong

回答

4
$("#dropdownlist").prop("selectedIndex", 1); 

這個jQuery代碼將下拉列表的選定選項設置爲第二個選項。

+0

不能,它仍然無法設置 –