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?
精彩评论