我正在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);