如下一段代碼:
<form action="calcSquare.php">
<p>
<label for=x>Number</label>:
<input id="x" name="x" type="number">
</p>
<script>
var x = document.getElementById('x');
var output = document.createElement('p');
output.textContent = 'Type a number; it will be squared right then!';
x.form.appendChild(output);
x.form.onsubmit = function () { return false; }
x.oninput = function () {
var v = x.valueAsNumber;
output.textContent = v + ' squared is ' + v * v;
};
</script>
<noscript>
<input type=submit value="Calculate Square">
</noscript>
</form>
這裡,x.form.appendChild(output),可以如此用嗎?誰能解釋一下?這是我我在W3C裡看到的一段代碼
input對象的form屬性為input所在form對象,ie8-不支持oninput和textContent屬性。oninput同時添加onpropertychange,textContent改為innerHTML