【问题标题】:How to populate message box from a text box when user enters a value?用户输入值时如何从文本框中填充消息框?
【发布时间】:2011-06-21 03:57:23
【问题描述】:

我使用 3 个文本框进行范围选择。当用户在文本框中输入范围时,我想在消息框中显示范围值。

假设用户进入

  1. 100 在第一个文本框中,我想显示“你被选中
  2. 第一个文本框为 100,第二个文本框为 500 我想显示“你被选中 101 - 500”
  3. 第 2 个文本框为 500,第 3 个文本框为 1000 我想显示“你被选中 501 - 1000”

在第三个文本框中输入值后,我想在消息框中显示所有范围。

我该怎么做?

【问题讨论】:

    标签: javascript asp.net


    【解决方案1】:

    看看我编写的这个例子

    http://jsbin.com/ovepo4

    【讨论】:

      【解决方案2】:

      您需要使用一些 javascript 从每个文本框中获取值,并通过 alert 函数将这些值显示在消息框中。

      假设您的文本框被称为“第一”、“第二”和“第三”,它看起来像这样:

      var firstValue = document.getElementByName('first').value;
      var firstValue = document.getElementByName('second').value
      var firstValue = document.getElementByName('third').value
      

      如果你使用 jQuery,你可以这样做:

      var firstValue = $('#first').val();
      var secondValue = $('#second').val();
      var thirdValue = $('#third').val();
      

      使用这些值,您可以执行一些逻辑,并显示您的信息,即:

      if(firstValue < 100) {
          alert('You entered < 100');
      }
      

      等等。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多