附加html并保留缩进

时间:2013-11-01 11:41:18

标签: php jquery

我需要在iframe内的php调用中使用jQuery追加一个html字符串(这是一个回复),但我还需要保留缩进。
基本上我发送一个回复到php,它会通过jquery发送它并发回它,但是我需要保留标记(标签,空格等),有没有办法做到这一点?此刻我用这个:

echo "<script>parent.$('#formreply').nimbleLoader('hide');parent.post_reply('".addslashes($_POST['message'])."','".$date."','".htmlspecialchars($_SESSION['name'],ENT_QUOTES,'UTF-8')."',".$json.");</script>";

但是我需要删除trim(preg_replace('/\s+/','',$_POST['message']))的所有商品,否则js会返回:unterminated string literal。这是一个帖子的示例(eco):

parent.$('#formreply').nimbleLoader('hide');parent.post_reply('<pre class=\"html\">
&lt;script&gt;
alert(\'ciao\')
alert(\'ciao\')
&lt;/script&gt;</pre>
<p> </p>','2013-11-01 12:29:58','Admin',null);

修改

function post_reply(mess, dat, name, up) {
        totalmsg++;
        <?php if(!$isMob){ ?> 
            CKEDITOR.instances.message.setData(''); 
        <?php } else { ?> 
            editor.setValue("", true); 
        <?php } ?> 
        $(".uploadfilebox").each(function () {
            $(this).remove()
        });
        $(".attlist").append("<div class='row-fluid uploadfilebox'></div>");
        tail = [];
        $("#messages").children(".row-fluid:first").hasClass("oddmessage") ? tail.push('<div class="row-fluid evenmessage" style="display:none"><div class="row-fluid"><div class="span2 usrinfo"><p class="username">' + name + '</p><p class="date">' + dat + '</p><p class="postnumber">Post Number: '+totalmsg+'</p></div><div class="span8 messagecell">' + mess + "</div></div>") : tail.push('<div class="row-fluid oddmessage" style="display:none"><div class="row-fluid"><div class="span2 usrinfo"><p class="username">' + name + '</p><p class="date">' + dat + '</p><p class="postnumber">Post Number: '+totalmsg+'</p></div><div class="span8 messagecell">' + mess + "</div></div>");
        if (null != up){
            tail.push('<div class="row attachment"><div class="span2 offset1 attachmentsec">Attachment</div><div class="span8">');
            var count= up.length;
            for (i=0; i < count; i++) 
                tail.push("<form class='download_form' method='POST' action='../php/function.php' target='hidden_upload' enctype='multipart/form-data'><input type='hidden' name='ticket_id' value='" + up[i][0] + "'/><input type='hidden' name='file_download' value='" + up[i][1] + "'/><input type='submit' class='btn btn-link download' value='" + up[i][2] + "'> &nbsp;&nbsp; <i class='icon-remove-sign remfile' title='Delete File' alt='Delete File'></i></form>");
            tail.push("</div></div>");
        }
        tail.push("</div>");
        $(".newest").remove();
        $("#messages").children(".row-fluid:first").before(tail.join(""));
        $("#messages").children(".row-fluid:first").delay(300).show('scale');
        $('#fielduploadinput').wrap('<form>').closest('form').get(0).reset();
        $('#fielduploadinput').unwrap();
        add++;
        writing=false;
    }

0 个答案:

没有答案