[英]My scripts doesn't work on Mozilla Firefox but does on Chrome
[英]Firefox doesn't run my scripts
我有一个简单的页面,它在IE和Safari中都很好用,但是Firefox拒绝运行脚本...谁能指出原因? (Firefox v 3.6.19)
脚本文件
// JavaScript Document
function spacesToPluses () {
var resu = myform2.input3.value.replace (/\W/g, '\+');
myform2.input4.value = resu;
}
function joinFieldsWithSpaces () {
var first = myform2.inputbox.value;
var second = myform2.input2.value;
var third = first+" "+second;
myform2.input3.value = third;
}
// GeoCoding Script
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(29.994638, -95.488186);
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
}
function codeAddress() {
var sAddress = document.getElementById("inputTextAddress").value;
var lon;
var lat;
var splittingPoint;
var stoppingPoint;
geocoder.geocode( { 'address': sAddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
myform.numberLoc.value = results[0].geometry.location;
alert(myform.numberLoc.value);
if (myform.numberLoc.value.indexOf(",")!=-1){
alert(myform.numberLoc.value.indexOf(","))
splittingPoint = myform.numberLoc.value.indexOf(",");
}
if (myform.numberLoc.value.indexOf(")")!=-1){
alert(myform.numberLoc.value.indexOf(")"))
stoppingPoint = myform.numberLoc.value.indexOf(")");
}
lat = myform.numberLoc.value.substring(1, splittingPoint);
lon = myform.numberLoc.value.substring(splittingPoint+2, stoppingPoint);
myform.myLat.value = lat;
myform.myLon.value = lon;
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
我正在使用的HTML文件在这里:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex/nofollow" />
<title>Test Input</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript"src="StringScripts.js"></script>
</head>
<body onload="initialize()">
<h1>String Manipulation</h1>
<form action="" method="get" name="myform2" id="myform2">Enter something in the box: <br />
<input type="text" name="inputbox" value="" /><br /><br />
<input type="text" name="input2" value="" /><br /><br />
<input type="button" name="button" value="Combine Field 1 and 2" onclick="joinFieldsWithSpaces()" /><br /><br />
<input type="text" name="input3" value="" /><br /><br />
<input type="button" name="button" value="Click to add Plus Signs to Box 3" onclick="spacesToPluses()" />
<br /><br />
<input type="text" name="input4" value="" /><br /><br />
</form>
<hr />
<br />
<h1>Geocoding</h1>
<form name="myform" id="myform">
<!--Create a text box input for the user to enter the street address-->
Address: <input type="text" id="inputTextAddress" style=" width:200px" title="Address to Geocode"/>
<!--Create a button input for the user to click to geocode the address-->
<input type="button" onclick="codeAddress()" id="inputButtonGeocode" style="width:150px" title="Click to Geocode" value="Click to Geocode" /><br /><br />
Latitude, Longitude: <input type="text" name="numberLoc" style=" width:200px" id="numberLoc" value="nothing entered yet" /><br /><br />
Latitude: <input type="text" name="myLat" style="width:125px" id="myLat" value="Null" /><br />
Longitude: <input type="text" name="myLon" style="width:125px" id="myLon" value="Null" />
</form>
</body>
</html>
任何帮助将不胜感激。 我从来没有遇到过这个问题。 我检查了FF并且启用了JavaScript,没有任何阻止,没有插件会干扰它。
我在这里真的很困惑,我敢肯定这将是我所缺少的一件事,并且会因不知道而踢自己。
好的,我发现了问题所在。 显然,Firefox要求您首先从文档(例如document.myform2.inputbox.value)中处理表单,而我丢失了“文档”。
将其插入列表即可,现在可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.