Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.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 如何将一个变量移到另一个html文件中,并根据该变量更改html文件上的文本_Javascript_Html - Fatal编程技术网

Javascript 如何将一个变量移到另一个html文件中,并根据该变量更改html文件上的文本

Javascript 如何将一个变量移到另一个html文件中,并根据该变量更改html文件上的文本,javascript,html,Javascript,Html,首先,我试图将一个变量传输到另一个html文件,但我认为我完全错了 这是我的第一页代码: <input type="text" placeholder="Enter Storage Size" name="storage size" id="storagesize" required> <label for="Colour"><b>Colour</b></label> <input type="text" placeholder=

首先,我试图将一个变量传输到另一个html文件,但我认为我完全错了

这是我的第一页代码:

<input type="text" placeholder="Enter Storage Size" name="storage size" id="storagesize" required>
<label for="Colour"><b>Colour</b></label>
<input type="text" placeholder="Enter Colour" name="Colour" id="colour" required>

<label for="Features"><b>Features</b></label>
<form>
<label class="container">FingerPrint Scanning Security 50$
<input type="checkbox" value="50" id="fingerprint">
<span class="checkmark"></span>
</label>

<label class="container">Feature Two 50$
<input type="checkbox" value ="50" id="two">
<span class="checkmark"></span>
</label>

<label class="container">Feature Three 50$
<input type="checkbox" value ="50" id="three">
<span class="checkmark"></span>
</label>

<label class="container">Feature Four 50$
<input type="checkbox" value ="50" id="four>
<span class="checkmark"></span>
</label>
</form>

<script>
var feature;
var size = document.getElementById("userInput").value;
var colour = document.getElementById("userInput").value;
localStorage.size = size
localStorage.colour = colour
('fingerprint').click(function() {
feature ="50";
localStorage.feature="50";
});
('two').click(function() {
feature ="50";
localStorage.feature="50";
});
('three').click(function() {
feature ="50";
localStorage.feature="50";
});
('four').click(function() {
feature ="50";
localStorage.feature="50";
 });

</script>`

颜色
特征
指纹扫描安全50$
特辑二50$
特色三50$
特色四50$

在URL中将变量作为参数传递,例如
www.mysite.com/otherpage?color=blue
。然后使用JavaScript将参数放入新/其他页面上的变量中

var getArg = getArg();
var color = getArg['color'];

function getArg(param) {
    var vars = {};
    window.location.href.replace(window.location.hash, '').replace(
        /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
        function(m, key, value) { // callback
            vars[key] = value !== undefined ? value : '';
        }
    );
    if (param) {
        return vars[param] ? vars[param] : null;
    }
    return vars;
}

我建议使用服务器端语言,比如PHP,如果你想创建一个电子商务,这是一个不错的选择。 localstorage适用于网站的简单(而不是基本)功能

对于长期应用程序来说,使用服务器端语言和会话将更容易、更好

var getArg = getArg();
var color = getArg['color'];

function getArg(param) {
    var vars = {};
    window.location.href.replace(window.location.hash, '').replace(
        /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
        function(m, key, value) { // callback
            vars[key] = value !== undefined ? value : '';
        }
    );
    if (param) {
        return vars[param] ? vars[param] : null;
    }
    return vars;
}