2015-10-28 34 views
0

當我點擊編輯(href鏈接)沿此我想要獲取相應的記錄數據時,我想重定向到新頁面。 這是視圖代碼如何通過ID作爲查詢字符串

<tr data-view-key="<?php echo $id; ?>"> 
    <td class=""><?php echo $id; ?></td> 
    <td class=""><?php echo $article_type; ?></td> 
    <td class=""><?php echo $abbr_article_type; ?></td> 
    <td class=""><?php echo $journal; ?></td> 
    <td class=""><?php echo $prefix_article_no; ?></td> 
    <td> 
     <a href="" name="edit_article_type">Edit</a> 
     | 
     <a href="#<?php echo $id; ?>" name="delete_article_type">Delete</a> 
    </td> 
</tr> 

這是JS

$(document).on("click", "a[name='edit_article_type']", function (event) 
    {   
     event.preventDefault(); 
     window.location = "add-article-type-details"; 
    }); 

在控制我想更新數據

+0

''Edit什麼問題?根本不需要JS。 –

回答

1

與查詢字符串發送:

$(document).on("click", "a[name='edit_article_type']", function (event){ 
    event.preventDefault(); 
    var id = $.trim($(this).closest('tr').find('td').eq(0).text()); 
    window.location = "add-article-type-details?id="+id; 
}); 
+0

謝謝男人:)。它的工作原理 – Ann

+0

不客氣@Ann – Jai

0
$(document).on('click', 'td > button.myEditButton', function(){ 
    url = 'add-article-type-details'; 
    id = $(this).closest('tr').data('view-key'); 
    window.location = url + '?id=' + id; 
)}; 

編輯:作爲你的ID是一個數據屬性在表格中,您聽取了<td></td>中按鈕的單擊事件。在事件中,它從父節點<tr></tr>中獲取data-view-key屬性,並重定向到給定的url並將id附加到它。

+0

你應該解釋你的答案 – Machavity

0
<tr data-view-key="<?php echo $id; ?>"> 
<td class=""><?php echo $id; ?></td> 
<td class=""><?php echo $article_type; ?></td> 
<td class=""><?php echo $abbr_article_type; ?></td> 
<td class=""><?php echo $journal; ?></td> 
<td class=""><?php echo $prefix_article_no; ?></td> 
<td> 
    <a href=""<?php echo site_url('controller/function') ?>/<?php echo $id ;?>" name="edit_article_type">Edit</a> 
    | 
    <a href="<?php echo site_url('controller/function') ?>/<?php echo $id ;?>" name="delete_article_type">Delete</a> 
</td> 

您可以使用Ajax作爲WEL嘗試這個http://w3code.in/2015/10/how-to-edit-delete-and-update-data-without-refreshing-page-in-codeigniter/