捕获并延迟 javascript onsubmit 事件
我正在使用一个 jQuery 插件,该插件将占位符添加到本机不支持它们的浏览器的输入中,并尝试在使用 Asp.Net 表单验证的表单上使用它。
在表单提交时,我将清除所有占位符值,以便它们不会提交,但验证不会报告空输入,因为它在清除我的输入之前触发。
有没有一种方法可以捕获表单 onsubmit 上的原始验证事件并将其存储起来,以便在我不需要时触发它?
我想这就是我需要捕捉的方法。
onsubmit="javascript:返回 WebForm_OnSubmit();"
$(function () {
// capture the original onsubmit event here.
// Look for forms
$("form").bind("submit.placeholder", function () {
// Clear the placeholder values so they don’t get submitted
var $inputs = $(".placeholder", this).each(clearPlaceholder);
// call the event here.
setTimeout(function () {
$inputs.each(setPlaceholder);
}, 10);
});
});
I'm using a jQuery plugin that adds placeholders to inputs for browsers that do not natively support them and am trying to use it on a form that uses Asp.Net form validation.
On form submit I'm clearing any placeholder values so they are not submitted but validation is not reporting an empty input as it is firing before my input is cleared.
Is there a way of capturing the original validation event on form onsubmit and storing it so that it fires when I wan't it to?
I think this is the method I need to capture.
onsubmit="javascript:return
WebForm_OnSubmit();"
$(function () {
// capture the original onsubmit event here.
// Look for forms
$("form").bind("submit.placeholder", function () {
// Clear the placeholder values so they don’t get submitted
var $inputs = $(".placeholder", this).each(clearPlaceholder);
// call the event here.
setTimeout(function () {
$inputs.each(setPlaceholder);
}, 10);
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会使用 eval 因为它很危险(或者有人这么说),但你知道由你决定。
顺便说一句,占位符用于 HTML 5 上的
I wouldnt use eval coz its dangerous (or so some say) but you know up to you.
by the way a placeholder is used on
<input type="text" placeholder="Search" />
on HTML 5