gpt4 book ai didi

php - 将 JS 添加到 Codeigniter 链接 - 简单的 OnClick

转载 作者:可可西里 更新时间:2023-11-01 00:27:17 25 4
gpt4 key购买 nike

我正在尝试将一个简单的 Javascript 片段写入 Codeigniter 链接。我正在使用链接删除仪表板中需要的帖子。我对 JS 一无所知,尽管我正在努力学习它。

代码

$js = 'onClick = "alert("Are you sure")"';

$this->table->set_heading('Date', 'Title', 'Delete', 'Update');

foreach($records as $row){
$row->title = ucwords($row->title);
$this->table->add_row($row->date,
$row->title = ucwords($row->title),
anchor("main/delete/$row->id", $row->id, $js), //this is the link in question
anchor("main/fill_form/$row->id", $row->id)
);
}
$table = $this->table->generate();
echo $table;

我的问题是如何为链接 ($js) 编写 JS。我想使用确认声明(是或否)。我完全迷失了 JS 以防止意外删除

谢谢

最佳答案

以下是使用 CodeIgniter anchor 函数的方法:

echo anchor('delete/something', 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));

单击链接时会显示一个确认框。如果用户确认,则点击链接。如果用户取消,则不执行任何操作。

关于php - 将 JS 添加到 Codeigniter 链接 - 简单的 OnClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3478268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com