Solution to secondary invalidation of setting checkbox value by JQuery

  • 2021-07-04 18:01:32
  • OfStack

In this MVC ASP. NET project, I use jquery ajax to transmit data to the background controller control layer and return data to JQuery data.

First of all, we must clear the selection of checkbox, because it is an asynchronous operation of ajax and does not refresh the page, so we need to recharge the control value by means to make it empty, which does not affect the next data display.

To get down to business, $("# checkboxID"). attr ('checked', false); //Set checkbox to unchecked,

$("# checkboxID"). attr ('checked', true); //Set checkbox to select.

Put two on one, and the page will always show unchecked status.

Later, I checked it and solved the problem with. prop.

I first empty the last selected state of chechbox $("# checkboxID"). prop ('checked', false);

Then when ajax submits the returned data, it is processed $("# checkboxID"). prop ('checked', true);


Related articles: