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开发者_StackOverflow中文版 $inputs = $(".placeholder", this).each(clearPlaceholder);
// call the event here.
setTimeout(function () {
$inputs.each(setPlaceholder);
}, 10);
});
});
var attrs = $('[onsubmit!=""]').attr('onsubmit');// gets the string of the on submit
$('[onsubmit!=""]').attr('onsubmit','');//remove the onsubmit text
eval(attrs);
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
精彩评论