元素在DIV刷新时消失


Elements Disappear on DIV Refresh

由于某种原因,当我显式调用div的刷新时,本应使用此代码加载到某些div中的元素将消失。如果我刷新整个页面,元素当然会返回。我到底做错了什么?

(function() {
$('div.heriyah').each(function() { 
$(this).html('<? if (!isset($_SESSION[''username2009''])) {} else { echo '"<div class='"add'"><div id='"add_button_container'"><div id='"add_button'" class='"edit_links'">  + Add Element</div></div></div><div class='"clear'"></div></div>'"; }?>');
 var curID = $(this).attr('id');//get the id before you go into fallr
$('.add').click(function() {
$.fallr('show', {
          content     :  '<iframe width="620" height="600" src="admin/add_content_select.php?pageID=<? echo $pageID; ?>&div='+ curID +'"></iframe>',
          width       : 320, // 100 = for width padding
          height         : 400,
              closeKey        : true,
              closeOverlay    : true,
              buttons     : {}
    }); 
    }); 
    }); 
})();

您需要转义$_SESSION中的引号。

'<? if (!isset($_SESSION[''username2009''])) ... '
                     //  ^             ^

这个部分还有一些逃避问题:

echo '"<div class='"add'"><div id='"add_button_container'"><div id='"add_button'" class='"edit_links'">  + Add Element</div></div></div><div class='"clear'"></div></div>'";

当对此进行评估时,它将如下所示:

echo "<div class="add"><div id="add_button_container"><div id="add_button" class="edit_links">  + Add Element</div></div></div><div class="clear"></div></div>";

这是无效的,要修复它,您需要在每个转义引号之前添加一个反斜杠。

echo '"<div class='''"add'''"><div id='''"add_button_container'''"><div id='''"add_button'''" class='''"edit_links'''">  + Add Element</div></div></div><div class='''"clear'''"></div></div>'";