为什么这个简单的Javascript重构不起作用



关于以HTML格式提交的表单的简单问题。

为什么这样做:

var inputStuff = document.getElementById("inputBox");
var output = document.getElementById("outputBox");
function useMethod(element) {
    output.innerText = inputStuff.value;
    return false; 
}

但这不会:

var inputStuff = document.getElementById("inputBox");
var output = document.getElementById("outputBox");
function useMethod(element) {
    var out = output.innerText;
    var into = inputStuff.value;
    out = into;
    return false; 
}

这是 HTML:

<h1>Put your input in here</h1>
    <form onsubmit="return useMethod(this)" action="">
        <input type="text" id="inputBox">
        <input type="submit" value="Submit">
    </form>
    <h2>Output:</h2>
    <p id="outputBox">Starter text</p>

提前非常感谢任何帮助,

R

out = into;将简单地将into(字符串(的值分配给out(字符串(,而output.innerText = inputStuff.value;将调用一个隐式资源库,该资源库也会更改DOM值。

最新更新