开发者

Simple jQuery assignment

I have a on change method defined for my drop-down as follows -

$(开发者_如何学Go"[name=engine]").change( function() {
  var selectedIndex = $(this).val() ;
  var selectedValue = $("#engine option[value=333]").text()
  alert("Change..." + selectedIndex + " - "+ selectedValue);        
});

Here instead of 333, i want to substitute the value of selectedIndex, how can I assign it to the option[Value= ??] element?


The same way you create the alert text: String concatenation.

$("#engine option[value='" + selectedIndex + "']").text()


$("[name=engine]").change( function() {
    var selectedIndex = $(this).val() ;
    var selectedValue = $("#engine option[value="+selectedIndex +"]").text()
    alert("Change..." + selectedIndex + " - "+ selectedValue);

});

did you try this?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜