我有一个像这样的简单表格:
<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>
我想捕获此表单的文本框焦点丢失(模糊)事件和选择框更改事件。
我不想对整个表单应用更改事件,因为它会导致多次提交表单。
最佳答案
将 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);
});
关于javascript - 如何在 prototypejs 中捕获表单字段的焦点丢失事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7902042/