【问题标题】:use javascript to print textfiled value to page使用 javascript 将文本字段值打印到页面
【发布时间】:2012-04-02 23:32:24
【问题描述】:

如何获取使用 javascript 输入文本字段的值并将其打印到页面?我可以使用警报来查看输入到文本字段中的值,但我无法从函数中获取值以将文本字段打印到页面。 我的代码在这里:http://jsbin.com/olokoq/2

【问题讨论】:

    标签: javascript function textfield document.write


    【解决方案1】:
    inside your html text field call a function on onkeyUp or relevent function 
    
    <input type='text' id='id1' onKeyUp='name(this.value);' value='name_value' />
    
    function
    <script>
    function name(var_value){
    document.getElementById("print").value = var_value; // print in a text field
    document.getElementById('prnt').innerHtml = var_value; // print in a division 
    }
    </script>
    
    <div id = 'prnt' ></div>
    
    <input type='text' id='print'  value='name_value' />
    

    【讨论】:

      【解决方案2】:

      SelectSubCat你需要添加以下内容:

      document.getElementById('value').innerHTML = txtValue;
      

      然后在你的html中添加:

      <span id="value"></span>
      

      这将在您单击按钮后立即将文本输入的值插入到 span 标签中。

      【讨论】:

      • 不起作用, 必须在脚本标签内吗?
      • 不,它必须在您的 html 正文中的某个位置(任何位置,这都不重要)
      • 它不起作用它只打印 You type: and i used

        You type:

        with document .getElementById('vvaluessss').innerHtml = txtValue;在 selectsubcat 中
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 1970-01-01
      • 2016-02-22
      • 2013-08-01
      相关资源
      最近更新 更多