我使用下面的代码<{1}}从id
获取URL
$(document).ready(function() {
var full_url = document.URL; // Get current url
var url_array = full_url.split('/') // Split the string into an array with / as separator
var last_segment = url_array[url_array.length-2]; // Returns Id
此id
是选择框
Ex:- <option value="37">xxx</option>
现在,我想将与此id
相关的文字显示为已选中。我怎么能用jQuery做到这一点?
我试过这个:
$("#field-projectId option[value=last_segment]")).val(last_segment).attr("selected", "true");
$("#field-projectId option[value=last_segment]").attr("selected", "selected");
$("#field-projectId").val(last_segment);
答案 0 :(得分:0)