我遇到了这一行代码的问题:var value = $("#opstina option:selected").val();
,但只有在Chrome浏览器中我得到了undefined的值。在FireFox和IE中,它正常工作,只有在Chrome中我得到了这个警告。有人知道原因吗?HTML代码是:
<select id="opstina" name="opstina">
<option value="0">Izaberite Mesto</option>
<option value="1" selected="selected">Novi Sad-grad 1</option>
<option value="2">Beograd-Stari Grad</option>
</select>
这是我的jQuery代码。
if ($("#drzava option:selected").length) {
$("select#opstina").attr("disabled","disabled");
$("select#opstina").html("<option>wait...</option>");
var id = $("select#drzava option:selected").attr('value');
$.post("select_opstina.php", {id:id}, function(data){
$("select#opstina").removeAttr("disabled");
alert( "html koji bi trebao biti upisan u select:\n\n" + data );
$("select#opstina").html(data);
});
if ($("#opstina option:selected").length) {
alert('Došao sam pred petlju');
var value = $("#opstina option:selected")[0].value;
alert(value);
var sel = $("#opstina").val();
if (sel!=0) {
alert('Ušao sam u petlju, i selektovano polje za opštinu je' + sel );
$("select#mesto").attr("disabled","disabled");
$("select#mesto").html("<option>wait...</option>");
var id= $("select#opstina option:selected").attr('value');
alert(id);
$.post("select_mesto.php", {id:id}, function(data){
alert("html koji bi trebao biti upisan u select:\n\n" + data );
$("select#mesto").removeAttr("disabled");
$("select#mesto").html(data);
});
}
}
}
}