开发者

Simple jQuery assignment

开发者 https://www.devze.com 2023-02-15 03:18 出处:网络
I have a on change method defined for my drop-down as follows - $(开发者_如何学Go\"[name=engine]\").change( function() {

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

精彩评论

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