Php br在输入div可编辑数据库时
所以我有一个div,我可以这样编辑:Php br在输入div可编辑数据库时,php,jquery,ajax,database,Php,Jquery,Ajax,Database,所以我有一个div,我可以这样编辑: if(isset($user_id)){ ?> <h2 id="title" onclick="makeEditable(this)" onblur="makeReadOnly(this)"><?php echo $out['title'];?></h2> <div id="text_div" onclick="makeEditable(this)" onblur="makeReadOnly(
if(isset($user_id)){
?>
<h2 id="title" onclick="makeEditable(this)" onblur="makeReadOnly(this)"><?php echo $out['title'];?></h2>
<div id="text_div" onclick="makeEditable(this)" onblur="makeReadOnly(this)">
<?php echo $out['text_html'];?>
</div>
<a class="button button1 logout" href="login/logout.php">Uitloggen</a>
<?php
}
还得到了这个函数在这里剽窃了一些其他的主题,所以
$('#text_div').keydown(function(e) {
// trap the return key being pressed
if (e.keyCode === 13) {
// insert 2 br tags (if only one br tag is inserted the cursor won't go to the next line)
document.execCommand('insertHTML', false, '<br><br>');
// prevent the default behaviour of return key pressed
return false;
}
});
$('#text_div').keydown(函数(e){
//按下返回键
如果(如keyCode===13){
//插入2个br标记(如果只插入一个br标记,光标将不会转到下一行)
document.execCommand('insertHTML',false,
');
//防止按下返回键的默认行为
返回false;
}
});
这可以正常工作,但如何在数据库中设置此
标记。目前,它在浏览器中正确地执行此操作,但当我刷新时,它会将所有内容放在后面
例如,我得到:
test
test
它在编辑时显示为:测试
测试
这是正确的,但当我使用ajax调用将其插入数据库并刷新页面时,它会像这样显示:测试测试
对我如何解决这个问题有什么建议吗 在数据库中插入某物之前,您可能会使用一些清理功能,例如strip_tags。问题是at
var text=$('#text_div').text()
它已经删除了所有的
,只显示了一个纯字符串testtesttest
@nosporAh,对了,我没有注意到这个文本()。所以你知道解决办法。只需使用.html()而不是.text():)在数据库中插入某个内容之前,您可能会使用一些清理功能,例如strip_tags问题是在var text=$('#text_div').text()处
它已经删除了所有的
,只显示了一个纯字符串testtesttest
@nosporAh,对了,我没有注意到这个文本()。所以你知道解决办法。只需使用.html()而不是.text():)
$('#text_div').keydown(function(e) {
// trap the return key being pressed
if (e.keyCode === 13) {
// insert 2 br tags (if only one br tag is inserted the cursor won't go to the next line)
document.execCommand('insertHTML', false, '<br><br>');
// prevent the default behaviour of return key pressed
return false;
}
});