我有以下 jQuery 工具覆盖:
<div id='editDescriptiontOverlay' class='overlay'>
<input type='text' class='description'/>
<button class='save'>Save</button>
<button class='close'>Cancel</button>
</div>
背景信息:此叠加层的 HTML 是静态的。我有一个项目列表,每个项目都有自己的编辑链接。单击给定的编辑链接时,将通过调用生成叠加层:$('a[rel=#editDescriptionOverlay]').overlay( { ... } );
并使用相应的文本填充输入。
当且仅当验证成功时,保存按钮需要验证输入元素中的文本并关闭覆盖。否则,覆盖必须保持打开状态。取消按钮只是关闭覆盖而不进行验证。
验证逻辑已经过独立验证可以正常工作。
我尝试onBeforeClose
在覆盖生成期间设置事件作为验证手段。采用这种方法,保存和取消按钮都需要相同的类.close
。不幸的是,该条件适用.close
于叠加层中的所有元素,因此即使是“取消”按钮也在验证。
我还尝试在生成叠加层后立即将单击事件绑定到“保存”按钮,如下所示:
$('.save', $('#editDescriptionOverlay'))
.unbind('click')
.bind('click', function() {
if (validateText) {
console.log("Validation passed.");
$('a[rel=#editDescriptionOverlay]').overlay().close();
}
else {
console.log("Validation failed.");
}
});
console.log 确认验证工作正常,但覆盖没有关闭。
任何见解表示赞赏,谢谢。