Php 如何在Javascript确认函数中传递参数?

Php 如何在Javascript确认函数中传递参数?,php,javascript,confirm,Php,Javascript,Confirm,我的代码中有类似的内容: <?php foreach($clients as $client): ?> <tr class="tableContent"> <td onclick="location.href='<?php echo site_url('clients/edit/'.$client->id ) ?>'"><?php echo $client->id ?></td>

我的代码中有类似的内容:

<?php foreach($clients as $client): ?>
    <tr class="tableContent">
        <td onclick="location.href='<?php echo site_url('clients/edit/'.$client->id ) ?>'"><?php echo $client->id ?></td>
        <td>
            <a class='Right btn btn-danger' onClick="ConfirmMessage('client', <?php $client->id ?>,'clients')">
                <i class="icon-remove-sign icon-white"></i>
            </a>
        </td>
    </tr>
<?php endforeach  ?>


将JavaScript中的字符串与
+
连接(与PHP中的
相比):


confirm
只接受一个参数(字符串),即显示给用户的消息。
如果要在该消息中插入变量,应使用
+
运算符连接字符串:

function ConfirmMessage(type, id, types) {
    if (confirm("Are you sure you want to delete this " + type + " ?")) { // Clic sur OK
       document.location.href='<?php echo site_url(); ?>' + types + '/delete/' + id;
    }
}
函数确认消息(类型、id、类型){
如果(确认(“您确定要删除此“+类型+”?”){//Clic sur OK
document.location.href=''+types+'/delete/'+id;
}
}
confirm("Are you sure you want to delete this " + type + " ?");
function ConfirmMessage(type, id, types) {
    if (confirm("Are you sure you want to delete this " + type + " ?")) { // Clic sur OK
       document.location.href='<?php echo site_url(); ?>' + types + '/delete/' + id;
    }
}