如何从退货确认中显示退货答案

时间:2013-09-04 10:12:40

标签: javascript

如何显示来自javascript return confirm()的提醒结果?

脚本是这样的:

<td width="25" align="center" title="Delete">
<?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="return confirm(\'Are you sure to delete '.$row->trans_code.'?\')">'?>
<img style="vertical-align:middle;"src="<?php echo site_url() . 'images/btn_delete.gif'; ?>"></img></a></td>

我想在确认后点击“是”后显示alert('Data deleted')

4 个答案:

答案 0 :(得分:6)

你需要创建一个onclick调用的函数 像

Demo

HTML / PHP

<?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="return myfunction(\''.$row->trans_code.'\')">'?>

的Javascript

function myfunction(transcode){
  if(confirm('Are you sure to delete '+ transcode + '?'))
  {
    //Delete data
    alert('data deleted');
    return true;
  }else{
    return false;
  }
}

答案 1 :(得分:6)

添加一个简单的JS函数:

function DeleteClick(transcode)
{
    if(confirm('Are you sure to delete ' + transCode + '?'))
    {
        alert('Data deleted');
        return true;
    }
    return false;
}

然后将您的电话改为

<?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="return DeleteClick(\''.$row->trans_code.'\')">'?>

答案 2 :(得分:3)

在onclick上写一个函数onclick =“confirmclick(userid);”

Javascript功能

function confirmclick(userid)
{
   var answer = confirm("Are you sure to delete " + userid + "?")

    if (answer){
        alert('Data deleted');
        return true;  
    }

    return false;  
} 

答案 3 :(得分:1)

如果您不想编写单独的功能,那么您可以使用以下内容。

<td width="25" align="center" title="Delete">
    <?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="if(confirm(\'Are you sure to delete '.$row->trans_code.'?\')){alert(\'Data deleted\');}">'?>
    <img style="vertical-align:middle;"src="<?php echo site_url() . 'images/btn_delete.gif'; ?>"></img></a></td>