简体   繁体   English

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

[英]Adding JS To Codeigniter Links - Simple OnClick

I am trying to write a simple Javascript snippet into a Codeigniter link. 我正在尝试将一个简单的Javascript代码段写入Codeigniter链接。 I am using the link to delete posts where required in my dashboard. 我正在使用该链接删除仪表板中所需的帖子。 I dont know anything about JS although am trying to learn it. 虽然我想学习它,但我对JS一无所知。

Code

$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;

My question is how to write the JS for the link ($js). 我的问题是如何为链接($ js)编写JS。 I would like to use a confirm statement, (yes or no). 我想使用确认声明(是或否)。 I am totally lost with JS to prevent accidental deletions 我完全迷失了JS,以防止意外删除

Thank you 谢谢

Here's how you might do it with the CodeIgniter anchor function : 以下是使用CodeIgniter锚点函数执行此操作的方法:

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

This displays a confirmation box when the link is clicked. 单击链接时会显示一个确认框。 If the user confirms then the link is followed. 如果用户确认,则遵循链接。 If the user cancels then no action is taken. 如果用户取消,则不采取任何措施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM