Confirmaction Issues
I'm currently using the confirmaction jQuery plugin found here:
http://www.webstuffshare.com/2010/03/jquery-plugin-jconfirmaction/
And my question is right now I have an icon that calls up the ask dialog box to ask if it wants to confirm the deletion of that one item however I also have a button that once clicked will create an array of values from checkboxes of it开发者_运维问答ems the user wants to delete and then confirm the deletion of those items but i'm having trouble dealing with multiple uses on the same page. Any suggestions.
Edit Post:
/*
* jQuery Plugin : jConfirmAction
*
* by Hidayat Sagita
* http://www.webstuffshare.com
* Licensed Under GPL version 2 license.
*
*/
(function($){
jQuery.fn.jConfirmAction = function (options) {
// Some jConfirmAction options (limited to customize language) :
// question : a text for your question.
// yesAnswer : a text for Yes answer.
// cancelAnswer : a text for Cancel/No answer.
var theOptions = jQuery.extend ({
question: "Are you sure?",
yesAnswer: "Yes",
noAnswer: "No"
}, options);
return this.each (function () {
$(this).bind('click', function(e) {
e.preventDefault();
thisHref = $(this).attr('href');
if($(this).next('.question').length <= 0)
$(this).after('<div class="question">'+theOptions.question+'<br/> <span class="yes">'+theOptions.yesAnswer+'</span><span class="no">'+theOptions.noAnswer+'</span></div>');
$(this).next('.question').animate({opacity: 1}, 300);
$('.yes').bind('click', function(){
if($('#myhiddenPageToken').val() == "useraccounts"){ useraccounts(this); }
else if($('#myhiddenPageToken').val() == "someotherpage"){ someotherfunction(); }
else{/*do nothing*/}
});
$('.no').bind('click', function(){
$(this).parents('.question').fadeOut(300, function() {
$(this).remove();
});
});
});
});
}
})(jQuery);
function useraccounts(whatsThis) {
var userID =$(whatsThis).parents('td').find('img').attr('id');
var dataString = 'userID=' + userID + '&deleteuser=True';
$.ajax({
type: "POST",
url: "processes/useraccounts.php",
data: dataString,
});
$(whatsThis).parents("tr").eq(0).hide();
}
<?php
session_start();
require("../inc/dbconfig.php");
require("../inc/global_functions.php");
// find out how many rows are in the table
$query = "SELECT CONCAT_WS(' ',firstName,lastName) AS name, username, emailAddress, userID FROM manager_users WHERE statusID != 4";
$result = mysqli_query($dbc,$query);
$fileName = basename($_SERVER['PHP_SELF']);
$pageName = "User Accounts";
$userData = $_SESSION['user_data'];
$userID = $userData['userID'];
?>
<script type="text/javascript">
$(document).ready(function() {
$('#usersPageList').dataTable( {
"sDom": 'rti<"pagination"p>',
"iDisplayLength": 10,
"sPaginationType": "full_numbers",
} );
var info = $('.dataTables_info')
var clone = info.clone();
info.hide();
$('tfoot tr td.rounded-foot-left').append(clone);
$('a.bt_green').click(function(e) {
e.preventDefault();
$('div.right_content').load('forms/addnew/' + $(this).attr('id'));
});
$('table tr').click(function() {
checkBox = $(this).children('td').children('input[type=checkbox]');
if(checkBox.attr('checked'))
checkBox.removeAttr('checked');
else
checkBox.attr('checked', 'checked');
});
$('.ask').jConfirmAction();
$('.ask2').jConfirmAction();
});
</script>
<h2>User Accounts</h2>
<table id="usersPageList" class="rounded-corner">
<thead>
<tr>
<th scope="col" class="rounded-first"></th>
<th scope="col" class="rounded">Name</th>
<th scope="col" class="rounded">Email Address</th>
<th scope="col" class="rounded">Username</th>
<th scope="col" class="rounded">Edit</th>
<th scope="col" class="rounded-last">Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5" class="rounded-foot-left"></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
<tbody>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"users[]\" value=\"".$row['userID']."\"/></td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['emailAddress']."</td>";
echo "<td>".$row['username']."</td>";
echo "<td><a href=\"#\"><img src=\"images/user_edit.png\" alt=\"\" title=\"\" border=\"0\" id=\"".$row['userID']."\" /></a></td>";
echo "<td>";
if (($row['userID'] !== '10000') && ($row['userID'] !== $userID)){
echo "<a href=\"#\" class=\"ask\"><img src=\"images/trash.png\" class=\"delete\" alt=\"\" title=\"\" border=\"0\" id=\"".$row['userID']."\" /></a>";
}
echo "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<?php
addRemove($fileName,$pageName);
?>
<input type="hidden" name="myhiddenPageToken" id="myhiddenPageToken" value="useraccounts" />
What I would do is give the button a certain class and then copy the content of the 'each'. Also you could make two 'theOptions' so you would have different texts, it's important to rename the classes 'yes' and 'no'. I'm not really familiar with your code so maybe if you post your HTML i can help you better.
return this.hasClass('class1').each (function () {
//the stuff you want to do here
}
return this.hasClass('class2').each (function () {
//the stuff you want to do here
}
精彩评论