select option by text using jquery
i use google map in my newest project ,and i have a combo box which contain a lot of places , this combo has two attributes(longitude,latitude) when my page loads i have function that plot markers for all places within this combo this function is here :
//Set All mohafzat markers
function setMohMarkers(){
//Loop Through mohafzat Combo
$("#moh").each(function(i){
//Remove Old Markers
//clearOverlays();
//loop Through it's Options
$('option',this).each(function(i){
var midx=$(this).index();
if(midx==0){
//Don't Plot 0 Index item
}else{
var idx=$(this).index();//get Current Index
var lon=$(this).a开发者_运维知识库ttr('lng');
var lat=$(this).attr('lat');
var mname=$(this).text();
//point's On Map
var myLatlng = new google.maps.LatLng(lat,lon);
//put Marker
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon:image,
//animation: google.maps.Animation.BOUNCE,
title:mname
});
google.maps.event.addListener(marker, 'click', function() {
map.setZoom(10);
map.setCenter(marker.latlng);
//Set mohafzat Combo to selected Marker
//$("#moh option:contains(" + marker.title +")").attr("selected","selected");
$('#moh option:[text="' + marker.title + '"]').attr('selected', true);
//Trigger Change Function
$("#moh option:contains(" + marker.title +")").trigger('change');
});
//push marker To my array(help me of deleting them :D)
Allmarkers.push(marker);
}});
//End Click Function
});
}
this code works very fine on internet explorer ,put with firefox when i click the marker for first time it zoom in to the selected place and if i have selected (index 0) of (select) tag it call this function to plot all places again and zoom out of map to show them all (till here every thing is fine) but if i have clicked the same marker again it do nothing ! don't even put content of marker title at my combo box at this line :
$('#moh option:[text="' + marker.title + '"]').attr('selected', true);
what makes me nervous that this code works very will on IE !!!!
The attr property was changed in jQuery 1.6:
See this question: .prop() vs .attr()
精彩评论