The page probably looks like this, a Partial View, and this View contains a small piece of Javascript bound to Search, and is included in the Jquery-ui dialog. And it is definitely not a problem with ASP.net mvc generating HTML. The HTML is based on my idea. Generated, but there was really no way to do it. I removed the dialog code and the Search button became normal. I checked the dialog code and found that it was caused by appendTo.
I did an experiment and the code is as follows:
Code
It is expected that alert('a1') should be executed once, but due to the use of appendTo, it is executed twice. Regardless of whether you use $(document).ready in the a1 div, javascript will be run twice. The first The document loading was completed for the first time, and appendTo was called for the second time.
First, it was changed to the following method, which failed.
Code
Change it to the following and you will be successful.
var loaded = false;
$(document) .ready(function() {
if (!loaded) {
alert('a1');
loaded = true;
}
});