我有一种情况,我需要以编程方式选择一个选项中的选项.我似乎无法找到答案,我的大脑正在变成糊状……这就是我一直在尝试的(和其他各种变化). $("#location_list option[value='"+LID+"']").att
$("#location_list option[value='"+LID+"']").attr("selected", "selected");
任何帮助将不胜感激!
谢谢!
这是周围的代码……
function loc_commitData(location_data, update_loc) { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { populate_loc_list('<?php echo $CompanyID; ?>', $("input:radio[name='locationstatus']:checked").val()); bind_events_to_location_list(); $("#location_list").val(xmlhttp.responseText); } } xmlhttp.open("GET", "includes/save_location_data.php?" + location_data, true); xmlhttp.send(); };
以下是在span标记中插入location_list的HTML片段…
<fieldset style="margin-right: 15px;"> <legend>Locations</legend> <span id="location_list_span"> THIS IS WHERE location_list GETS INSERTED ON THE FLY AFTER THE PAGE IS CREATED BY PHP</span> </fieldset>试试这个:
$("#location_list").val(LID);
设置下拉值should do the trick.