Confirm box always displays first (javascript, jQuery, .Net)
I have a jQuery-Script to accomplish the following tasks:
- if a gridview in my form contains a row with a certain id, it has to be marked red.
- a confirm dialogue has to pop up to ask the user if he wants to do this or that.
I built this code:
if (response == "EntryInList") {
$('#entryListContainer div table tbody tr').each(function() { 开发者_如何学JAVA
if ($(this).attr('id') == 'entry_' + $('#<%= txtProductNumber.ClientID %>').val()) {
$(this).css("color", "red");
}
}
);
if (!confirm("Entry already exists. Really overwrite?")) {
jQuery('#<%= txtProductNumber.ClientID %>').val('');
jQuery('#<%= txtCount.ClientID %>').val('');
jQuery('#<%= txtProductNumber.ClientID %>').focus();
return false;
}
}
As a result, the confirm box pops up first, without the row being turned red. Only after using the box, it becomes red. How would I get the row to be turned red at once?
Another of my problems is that the confirm box denies my page to be scrolled down. But I would like to do this if the gridview is longer than the entire page.
The display will not update until your JavaScript code finishes executing and the confirm
dialog is modal, which will halt all scripts until the dialog is closed. This means you won't see any changes to the document until after the box is closed, even though those changes have taken place.
A viable solution might be to display the box using setTimeout(function () {}, 0)
, but you might have to rework your other code a bit.
精彩评论