0

我需要使用 jQuery 从 iframe 内的 php 调用中附加一个 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
这是一个帖子的例子(the 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;
    }
4

0 回答 0