Javascript Firefox没有';不要运行我的脚本
我有一个简单的页面放在一起,它在IE和Safari中工作得很好,但Firefox拒绝运行脚本。。。有人能指出原因吗?(FirefoxV3.6.19) 脚本文件Javascript Firefox没有';不要运行我的脚本,javascript,html,firefox,Javascript,Html,Firefox,我有一个简单的页面放在一起,它在IE和Safari中工作得很好,但Firefox拒绝运行脚本。。。有人能指出原因吗?(FirefoxV3.6.19) 脚本文件 // JavaScript Document function spacesToPluses () { var resu = myform2.input3.value.replace (/\W/g, '\+'); myform2.input4.value = resu; } function joinFieldsWith
// 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)寻址表单,因为我缺少“文档”
将它插入列表中,现在就可以工作了。安装firebug扩展并查看它在控制台中显示的错误。脚本末尾的
}
括号不匹配。删除它。同样在'\+'
中,``是不必要的。Mike,如果我去掉最后一个括号,它会报告它有不均匀的括号,我手动阅读它,它看起来是平衡的。至于\+周围的“”,如果我去掉它们,我会再次出错。使用Firebug,它告诉我“myform2未定义”,在spacesToPluses()
和joinFieldsWithSpaces()
中都是这样。试着在Javascript中更改它(例如,myform2.input4.value=resu;
到myform.input4.value=resu;
),只要你看到myform2
。搜索和替换工程伟大!