0

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

1 回答 1

0

请尝试此代码

     $('#ddlWeeklyWeightIn').on("change", function () {
            alert($(this).val());
        });

请参考 Demo 链接See Demo

于 2013-05-06T12:33:26.580 回答