【问题标题】:Calling javascript function with button and input from textbox使用按钮调用javascript函数并从文本框输入
【发布时间】:2013-10-12 21:30:12
【问题描述】:

我的页面中有一个文本框和按钮。我有几套以下用于不同目的。

<input type="text" id="new" name="new" value="1" />
<input type="button" value="Edit" onclick="compute(edit(xxx));" />

单击按钮后,我想调用一个 javascript 函数,该函数将接收文本框中输入的值。现在我想知道如何从输入“new”中检索值并将“xxx”作为参数传递给它?

【问题讨论】:

  • 试试compute(edit(document.getElementById('new').value))

标签: javascript html function button textbox


【解决方案1】:

试试

<input type="button" value="Edit" onclick="compute(edit(document.getElementById('new').value));" />

【讨论】:

    【解决方案2】:

    你为什么不通过 Jquery 来尝试它是为了理解和易于实现。

    Jquery Documentation

    $('input[type=button]').click(function(){
    alert($('#new').val());// to get input text value
        $('#new').val('xxx');//to set input text value
    });
    

    你的问题小提琴Here

    【讨论】:

      【解决方案3】:
      <input type="button" value="Edit" onClick="compute(edit(document.getElementById('new').value))" />
      

      这就是您在 HTML 中处理它的方式。

      否则,您可以在 javaScript 中编写相同的代码。

      function edit()
      {
           x = document.getElementById('new').value;
           //use this X.
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-30
        • 2014-04-08
        • 2016-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-29
        相关资源
        最近更新 更多