2010-08-13 83 views
3

我正在嘗試將一個簡單的JavaScript代碼段寫入Codeigniter鏈接。我正在使用該鏈接刪除我的信息中心所需的帖子。我不知道任何關於JS的知識,儘管我正在努力學習它。將JS添加到Codeigniter鏈接 - 簡單的OnClick

代碼

$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失去了防止意外刪除

謝謝

回答

7

以下是你可能如何與笨錨功能做到這一點:

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

鏈接被點擊時,這會顯示一個確認框。如果用戶確認,則遵循鏈接。如果用戶取消,則不採取任何行動。

+0

非常感謝你。我應該很早以前就學會了JS。您讚賞 – Brad 2010-08-13 17:03:17

+0

偉大的:-)很高興幫助。 – 2010-08-13 19:26:39