【问题标题】:focusout on any TextBox关注任何文本框
【发布时间】:2017-02-13 12:42:00
【问题描述】:

我想调用一个文本框的javascript函数on focusout。我有很多TextBoxes,所以为了防止每个TextBox 都有一个监听器,是否有可能在任何textBox focusout 上调用相同的javascript 方法,并将文本框的值作为参数传递?

我想在客户端而不是在服务器端执行此操作。

【问题讨论】:

    标签: javascript jquery asp.net jquery-focusout


    【解决方案1】:

    有了jQuery,就这么简单

    $("input").focusout(function(){
        //Whatever you want
    });
    

    正如 Milney 所指出的,您可能希望与该特定文本框进行交互。为此,您可以使用“$(this)”作为选择器。

    $("input").focusout(function(){
        $(this).css("background-color", "beige");
    });
    

    【讨论】:

    • 注意:如果您需要访问触发事件的特定文本框,您可以在事件处理程序中使用 $(this)
    • 这大概就是他一开始就想知道的。我继续将其放在答案中,感谢您指出!
    【解决方案2】:

    使用

    $("input").focusout(function(){
      var tBval = $(this).val();
      console.log(tBval);
      
      // OR Call a function passing the value of text box as parameter
      //myFunction(tBval);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />

    【讨论】:

      【解决方案3】:

      当字段失去焦点时会发生模糊事件。

      试试这个:

      $("input").blur(function(){
       //alert("ok")
      });
      

      【讨论】:

        猜你喜欢
        • 2011-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-14
        • 1970-01-01
        • 2011-10-08
        相关资源
        最近更新 更多