简体   繁体   中英

jQuery functionality disappear in ASP.NET MVC partial view

I have a asp.net MVC partial view, inside it jQuery is used to popup a datepicker for a textbox. A cancel button using Ajax to reload the partial view when it is clicked. All work well in the first load. But after the cancel button is clicked, all the jQuery functionality disappear, for example the datepicker stop showing up for the textbox. Any idea what could be wrong with it?

如果您通过ajax对部分视图进行任何更新,则使用jquery绑定的任何事件都需要使用jquery live或jQuery on 1.7+进行反弹或绑定。

$(document).on(events, selector, data, handler);        // jQuery 1.7+

When you reload your partial view any handlers on the elements in the old (now replaced) partial will have been lost. You have to rebind them to get the functionality back.

A script block at the end of your partial that binds the handlers would work. Or the code that handles the AJAX success or complete call back can rebind them if you prefer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM