开发者

jQuery, Forms, Browser Refreshes

开发者 https://www.devze.com 2022-12-23 01:28 出处:网络
I have a large form with some fields values dependent on previous elements. I use jquery\'s .trigger event to trigger the dependent field\'s update functions. When I refresh the page (click reload or

I have a large form with some fields values dependent on previous elements. I use jquery's .trigger event to trigger the dependent field's update functions. When I refresh the page (click reload or click back), the previous values selected are still there, but the dependent fields are not reflecting the other element's values. How can I trigger the update functions upon refresh? I saw a way to prevent the browser from using the form's cached values. I'd rather use the cached values and update the elements dependent on the elements with cached values.

Edit: To illustrate the form:

<form>
    <input id="element1" /开发者_如何学C>
    <input id="element2_dependent_on_element1" />
</form>

element1 remains correct, but element2_dependent_on_element1 .change event is not triggered.


Why don't you do .trigger on all of the full inputs at the end of document.ready? That should fire all of them off when the page reloads.


You can either call form.reset() (DOM function, not a jQuery one) or, trigger the event handlers you're binding immediately after attaching them, for example:

$(function() {
  $("input").change(function() {
    //do something....
  }).change(); //trigger the handler once on load
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号