Wednesday, June 17, 2015

JavaScript, simple alert dialog callback




In java Script, when we create alert box and click OK, we hope some actions are performed.
The Modal dialog box, jquery dialog box and bootbox dialog box have similar features.
But the following codes are simplest:

for example, a table with a column with delete icon:
<tr class='template'><td class='delete' ><span class='btn glyphicon glyphicon-trash'></span></td></tr>
After clicking delete ico, this row is deleted after click ok in alert box:
 $('td.delete').on('click', function(){
                 var answer = confirm("Are you sure to delete this row?");
                if (answer)
                $(this).parents('tr').remove();
                                                         
   }); 

 

No comments:

Post a Comment