donglun7151 2015-01-15 10:03
浏览 42
已采纳

撇号不会让我删除项目

I have a CMS where I can create/delete items/menus/pages etc. I have a onclick jquery script that deletes something once you click an icon. Problem I am having is that when I have a page/menu/item with an apostrophe within its name, I am unable to delete it.

Here is snippets of my code:

jquery:

function confirmDeleteMenuItem(mi_id, mi_name) {
if (confirm('Are you sure you want to delete the menu item \''+mi_name+'\'?
Note: All sub-items will also be deleted.')) {
    $.ajax({
        dataType:  'json',
        url: cmsRelPath+'/app/menus/ajax_delete_menu_item.php',
        type: 'POST',
        data: {
            mi_id: mi_id
        },

php:

$cell .= '<img src="'.$cms_settings["cms_relative_dir"].'/images/icon_delete.png" width="30" height="30" border="0" alt="delete" title="Click to delete item." class="cursorPointer" onclick="confirmDeleteMenuItem('.$row->mi_id.',\''.html_entities($row->mi_name).'\');" />';

Could anyone help me with this issue?

  • 写回答

2条回答 默认 最新

  • douaoj0994 2015-01-15 10:14
    关注

    You can use double quotes in confirm():

    if (confirm('Are you sure you want to delete the menu item "'+mi_name+'"?
    Note: All sub-items will also be deleted.')) {
    /* ............ */
    

    and PHP:

    $cell .= '<img src="'.$cms_settings["cms_relative_dir"].'/images/icon_delete.png" width="30" height="30" border="0" alt="delete" title="Click to delete item." class="cursorPointer" onclick="confirmDeleteMenuItem('.$row->mi_id.',\''.html_entities(str_replace("'", "\'", $row->mi_name)).'\');" />';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?