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条)

报告相同问题?

悬赏问题

  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥30 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题