【问题标题】:How to capture form's fields focus lost event in prototypejs如何在prototypejs中捕获表单的字段焦点丢失事件
【发布时间】:2011-12-15 16:00:22
【问题描述】:

我有一个这样的简单表格:

<form id='myForm'>

    <input type='text' name='Textbox'>

    <select name='SelectBox'>
     <option class='option1'>option 1</option>
     <option class='option2'>option 2</option>
   </select>

</form>

我想捕获此表单的文本框焦点丢失(模糊)事件和选择框更改事件。

我不想为整个表单应用更改事件,因为它会导致多次提交表单。

【问题讨论】:

    标签: javascript forms event-handling prototypejs


    【解决方案1】:

    $('input').focus_lost(function() { /写出代码需要的东西/ });

    $('option').change(function() { /写出代码需要的东西/ });

    /这仅适用于这个给定的表格。从a link >和http://jqueryui.com/了解更多信息/

    【讨论】:

      【解决方案2】:

      id='SelectBox' 添加到您的选择框,将id='Textbox' 添加到您的文本框,然后尝试以下操作:

      function handleTextBoxBlur(event, element) {
        console.log("blur");
        console.log(element);
      }
      function handleSelectBoxChange(event, element) {
        console.log("change");
        console.log(element);
      }
      
      document.observe("dom:loaded", function(event) {
      
        $("Textbox").on("blur", "input", handleTextBoxBlur);
        $("SelectBox").on("change", "select", handleSelectBoxChange);
      
      });
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-19
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多