How to capture form's fields focus lost event in prototypejs

大城市里の小女人 提交于 2020-01-05 07:08:05

问题


I have a simple form like this:

<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>

I want to capture this form's Textbox focus lost (blur) event and SelectBox change event.

I don't want to apply change event for whole form because it causing to submit form more than one time.


回答1:


Add id='SelectBox' to your select box and id='Textbox' to your text box and try the following:

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);

});



回答2:


$('input').focus_lost(function() { /write what Ever code need/ });

$('option').change(function() { /write what Ever code need/ });

/This is suitable only for this given form..Learn more from a link >and http://jqueryui.com//



来源:https://stackoverflow.com/questions/7902042/how-to-capture-forms-fields-focus-lost-event-in-prototypejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!