Firefox不运行我的脚本

时间:2012-08-09 16:07:19

标签: javascript html firefox

我有一个简单的页面放在一起,它在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 />


        &nbsp;&nbsp;&nbsp;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,我没有任何阻止,没有插件会干扰它。

我真的很困惑,我相信这将是一件我想念的小事,并会因为不知道而自责。

1 个答案:

答案 0 :(得分:0)

好的,我发现了什么问题。显然,Firefox要求您先从文档中处理表单(例如,document.myform2.inputbox.value)我错过了“文档”。

将其插入列表中并立即生效。