JavaScript在html5输出标记中显示html文本输入

时间:2012-12-16 12:25:36

标签: javascript html html5 html-form

我正在尝试制作一个小的JavaScript网络应用程序,我可以用它来制作我要制作的网页模板。(加快设计和填充。) 但是当我这样做时,我想在我打字时让它更新。我知道可以用this来完成,但我觉得它有点乱。所以我试图使用html5输出元素,但我不能使它与文本字符串兼容,而不是只与数字兼容。 以下仅适用于数字:

<html>
    <body>
         <form oninput="x.value=parseInt(a.value)+parseInt(b.value)">
             <input type="range" name="a" value="50">
             <input type="number" name="b" value="50">
             <output name="x" for="a b"></output>
         </form>
    </body>
</html>

PS:我是JS的新手,只需要与FF兼容。

1 个答案:

答案 0 :(得分:2)

试试这个 - DEMO

<form oninput="xx.value=aa.value+bb.value">
    <input type="text" name="aa" value="hello">
    <input type="text" name="bb" value="world">
    <output name="xx" for="aa bb"></output>
</form>