简体   繁体   English

Firefox无法运行我的脚本

[英]Firefox doesn't run my scripts

I have a simple page put together and it works great in IE, and Safari, but Firefox refuses to run the scripts... Can anyone pinpoint why? 我有一个简单的页面,它在IE和Safari中都很好用,但是Firefox拒绝运行脚本...谁能指出原因? (Firefox v 3.6.19) (Firefox v 3.6.19)

The Script File 脚本文件

// 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);
        }
      });
  }

The HTML file I'm using is here: 我正在使用的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>​

Any help would be greatly appreciated. 任何帮助将不胜感激。 I have never run into this problem before. 我从来没有遇到过这个问题。 I checked FF and I have JavaScript enabled, I don't have anything blocked, no plugins that would interfere with it. 我检查了FF并且启用了JavaScript,没有任何阻止,没有插件会干扰它。

I really am confused here, and I'm sure it's going to be one tiny thing I'm missing and will kick myself for not knowing. 我在这里真的很困惑,我敢肯定这将是我所缺少的一件事,并且会因不知道而踢自己。

Ok, I found out what was wrong. 好的,我发现了问题所在。 Apparently Firefox requires you to address the form from document first (eg, document.myform2.inputbox.value) I was missing the "document." 显然,Firefox要求您首先从文档(例如document.myform2.inputbox.value)中处理表单,而我丢失了“文档”。

Plugged that in down the list and it works now. 将其插入列表即可,现在可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的脚本无法在Mozilla Firefox上运行,但可以在Chrome上运行 - My scripts doesn't work on Mozilla Firefox but does on Chrome 为什么JavaScript无法在Firefox中运行? - Why doesn't this JavaScript run in Firefox? Firefox不运行setInterval函数(最新的Firefox) - Firefox doesn't run setInterval function (the latest Firefox) 我的Internet Explorer(版本11)未加载外部脚本 - My Internet Explorer (version 11) doesn't load external scripts 咖啡脚本在我的ruby应用程序中不起作用 - coffee scripts doesn't work in my ruby app addEventListener(“loadedmetadata”,fun)无法正常运行,Firefox错过了事件 - addEventListener(“loadedmetadata”,fun) doesn't run correctly ,Firefox misses event 量角器启动 Firefox 但不运行任何测试 - Protractor starts Firefox but doesn't run any tests 功能在Chrome中运行,但在Firefox中未运行,表示功能未定义 - Function runs in Chrome but doesn't run in Firefox says function not defined angular 7应用程序无法在firefox中运行,并且在chrome和edge中运行良好 - angular 7 app doesn't run in firefox and runs well in chrome and edge 在所有脚本都准备就绪之前,Safari不会渲染,不像Chrome或Firefox - Safari doesn't render until all scripts are ready not like Chrome or Firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM