Javascript 下拉菜单及其功能的问题
我创建了一个简单的下拉菜单,其中包含函数。然后我意识到在我执行Function之后,我不能再执行它了。我必须先执行functionB(另一个函数),然后才能再次执行functionA。。。我可以知道如何解决这个问题吗?下面是我的代码 谢谢Javascript 下拉菜单及其功能的问题,javascript,html,drop-down-menu,Javascript,Html,Drop Down Menu,我创建了一个简单的下拉菜单,其中包含函数。然后我意识到在我执行Function之后,我不能再执行它了。我必须先执行functionB(另一个函数),然后才能再次执行functionA。。。我可以知道如何解决这个问题吗?下面是我的代码 谢谢 function changeForm(the_form) { window.location = the_form; } //Add Markers by Latitude and Longitude, automatically //Lis
function changeForm(the_form)
{
window.location = the_form;
}
//Add Markers by Latitude and Longitude, automatically
//Listen for click
function marker()
{
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng);
});
}
// Place markers in by click
function addMarker(location) {
marker = new google.maps.Marker({
position: location,
map: map,
title:"Specified Location",
icon: 'images/greenPoint.png'
});
markersArray.push(marker);
}
// Choose By Latitude and Longitude, manually
function admarker()
{
var lat = prompt("Enter latitude (-90 to 90)", "0");
while ((lat < -90) || (lat > 90))
{
alert("Latitude must be between -90 to 90");
var lat = prompt("Enter latitude (-90 to 90)", "0");
}
var lng = prompt("Enter longitude (-180 to 180)", "0");
while ((lng < -180) || (lng > 180))
{
alert("Longitude must be between -180 to 180");
var lng = prompt("Enter latitude (-180 to 180)", "0");
}
lat = parseInt(lat);
lng = parseInt(lng);
var latlng = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
clickable: true,
title:"Specified Location",
icon: 'images/bluePoint.png'
})
var infiwindow = new google.maps.InfoWindow({
content: "Place where you have chosen!"
});
google.maps.event.addListener(marker,'mouseover',function(){
infiwindow.open(map,marker);
});
google.maps.event.addListener(marker,'mouseout',function(){
infiwindow.close(map,marker);
});
函数变更表(函数变更表)
{
window.location=_表单;
}
//自动按纬度和经度添加标记
//听一听咔嗒声
函数标记()
{
google.maps.event.addListener(映射,'click',函数(事件){
添加标记(事件标记);
});
}
//通过单击将标记放置到中
功能添加标记(位置){
marker=新的google.maps.marker({
位置:位置,,
地图:地图,
标题:“指定位置”,
图标:“images/greenPoint.png”
});
markersArray.push(marker);
}
//手动按纬度和经度选择
函数admarker()
{
var lat=提示(“输入纬度(-90到90)”,“0”);
而((纬度<-90)| |(纬度>90))
{
警报(“纬度必须在-90到90之间”);
var lat=提示(“输入纬度(-90到90)”,“0”);
}
var lng=提示(“输入经度(-180到180)”,“0”);
而((液化天然气<-180)| |(液化天然气>180))
{
警报(“经度必须介于-180到180之间”);
var lng=提示(“输入纬度(-180到180)”,“0”);
}
lat=parseInt(lat);
液化天然气=parseInt(液化天然气);
var latlng=新的google.maps.latlng(lat,lng);
var marker=new google.maps.marker({
位置:latlng,
地图:地图,
可点击:正确,
标题:“指定位置”,
图标:“images/bluePoint.png”
})
var infiwindow=new google.maps.InfoWindow({
内容:“你选择的地方!”
});
google.maps.event.addListener(标记,'mouseover',function(){
infiwindow.open(地图、标记);
});
google.maps.event.addListener(标记,'mouseout',函数(){
infiwindow.close(地图、标记);
});
}
--按横向和纵向添加标记--
手动添加标记
自动添加标记
问题在于,当选择框的值更改时,代码会运行,当然,一旦选择了一个选项,只需再次单击它就不会更改该值
您可能只需添加this.selectedIndex=0代码>到您的onChange
:
<select name = "the_select" onChange = "changeForm(this.value); this.selectedIndex = 0;">
问题是,当选择框的值更改时,代码会运行,当然,一旦选择了一个选项,再次单击它不会更改该值
您可能只需添加this.selectedIndex=0代码>到您的onChange
:
<select name = "the_select" onChange = "changeForm(this.value); this.selectedIndex = 0;">
我认为,如果您将代码格式化并按以下方式进行排列,它将很好地工作:-
我知道您想根据下拉菜单中选择的选项更改表单
如果我的理解正确,我希望它能帮助您:
--
功能变更表(_表)
{
window.location=”http://mywebsite/“+the_form+”.html”;
}
按横向和纵向添加标记(&L)
手动添加标记
自动添加标记
--我认为,如果您将代码格式化并按以下方式排列,它将很好地工作:-
我知道您想根据下拉菜单中选择的选项更改表单
如果我的理解正确,我希望它能帮助您:
--
功能变更表(_表)
{
window.location=”http://mywebsite/“+the_form+”.html”;
}
按横向和纵向添加标记(&L)
手动添加标记
自动添加标记
--您需要再次格式化。使用101010图标将其缩进4个空格,使其显示为code。您还可以发布functionA
和functionB
的代码。您需要再次格式化。使用101010图标将其缩进4个空格,使其显示为code。您还可以发布function
和functionB
的代码。
<form name = "formTwo">
<select name = "the_select" onChange = "changeForm(this.value); this.selectedIndex = 0;">
<option value = "#">- - Add Markers By Lat & Long - -</option>
<option value = "adMarker">Add Markers Manually</option>
<option value = "readMarker">Add Markers Automatically</option>
</select></form>
<script type='text/javascript'>
function changeForm(the_form)
{
switch (the_form) {
case "adMarker":
// Do something
display("ad marker");
break;
case "readMarker":
// Do something else
display("read marker");
break;
}
}
</script>