Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要关于使用1个js文件的多个页面上的全局变量的帮助吗_Javascript_Jquery - Fatal编程技术网

Javascript 需要关于使用1个js文件的多个页面上的全局变量的帮助吗

Javascript 需要关于使用1个js文件的多个页面上的全局变量的帮助吗,javascript,jquery,Javascript,Jquery,在我的主页上有两个输入字段(FromZip和ToZip)。除此之外还有一个标记,用于调用函数窗口。打开。这两个输入应仅共享一个弹出页面。此弹出页面将允许用户选择一个州和城市,生成的zipcode将发布在主页上。以下是一些代码: 首页(html): 所以发生的情况是:home->用户单击帮助按钮->选择城市->选择州->下拉列表生成zip->单击提交->主页上发布的zip值。但是,由于2共享同一个窗口。打开,我不知道如何告诉脚本在上发布,是从zip还是从到zip,不清楚您在问什么,但这应该会有所帮

在我的主页上有两个输入字段(
FromZip
ToZip
)。除此之外还有一个
标记,用于调用函数
窗口。打开
。这两个输入应仅共享一个弹出页面。此弹出页面将允许用户选择一个州和城市,生成的zipcode将发布在主页上。以下是一些代码:

首页(html):


所以发生的情况是:
home->用户单击帮助按钮->选择城市->选择州->下拉列表生成zip->单击提交->主页上发布的zip值
。但是,由于2
共享同一个
窗口。打开
,我不知道如何告诉脚本在
上发布,是从zip
还是从
到zip
,不清楚您在问什么,但这应该会有所帮助

赋值语句应使用单个
=

function openpage() {
    choice = "FromZip";
    window.open('http://cheapestmovingquote.com/zipcodehelper/ResidentialFromZip.php', 'popUpWindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no');
}

function openpage2() {
    choice = "ToZip";
    window.open('http://cheapestmovingquote.com/zipcodehelper/ResidentialFromZip.php', 'popUpWindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no');
}

基本页和首页上加载的是同一个javascript文件吗?这两个页面在同一个域上吗?
var choice;
function openpage() {
    choice == "FromZip";
    window.open('http://cheapestmovingquote.com/zipcodehelper/ResidentialFromZip.php', 'popUpWindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no');
}

function openpage2() {
    choice == "ToZip";
    window.open('http://cheapestmovingquote.com/zipcodehelper/ResidentialFromZip.php', 'popUpWindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no');
}

function post_value() {
    if (choice == "FromZip") {
        alert(window.choice);
        window.opener.document.getElementById("RFromZip").value = document.getElementById("cityBox").value;
        self.close();
    }

    if (choice == "ToZip") {
        alert(window.choice);
        //window.opener.document.getElementById("RToZip").value = document.getElementById("cityBox").value;
        self.close();
    }

}
function openpage() {
    choice = "FromZip";
    window.open('http://cheapestmovingquote.com/zipcodehelper/ResidentialFromZip.php', 'popUpWindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no');
}

function openpage2() {
    choice = "ToZip";
    window.open('http://cheapestmovingquote.com/zipcodehelper/ResidentialFromZip.php', 'popUpWindow', 'height=300,width=500,left=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=no');
}