gpt4 book ai didi

php - Textarea 不使用 ajax 更新换行符

转载 作者:行者123 更新时间:2023-11-30 22:55:06 25 4
gpt4 key购买 nike

我有一些文本以下面的格式存储在 mysql 表中:

  • 这是演示行 1
  • 这是演示行 2
  • 这是演示行 3
  • 这是演示行 4
  • 这是演示行 5

但是,当我更新文本区域中的任何行时,它会显示以下输出。实际上,如果我不更新它以在文本中输出上述内容,我会尝试用它制作一个文本文件文件但是,当我更新内容以在文本文件中提供以下输出时。

这是我的代码:

This is the demo line 1 This is the demo line 2This is the demo line 3This is the demo line 4This is the demo line 5

<table>
<tr class="head">
<th style="display: none">Lable Name</th>
<th style="display: none">Tag Details</th>
</tr>
<?php
$sql1 = "SELECT * from tagto_print where print_tag_id='8'";
$reslabel=mysql_query($sql1);
$i=1;
while($row=mysql_fetch_array($reslabel))
{
$printid=$row['print_tag_id'];
$tagdetailstoprint=$row['print_tag_details'];
?>
<tr id="<?php echo $printid; ?>" class="edit_tr">
<td width="10%"><?php echo $row['print_tag_labelname'];?></td>
<td width="50%" class="edit_td">
<span id="details_<?php echo $printid; ?>" class="text"><pre><?php echo $tagdetailstoprint; ?></pre></span>
<textarea class="form-control" id="details_input_<?php echo $printid; ?>" rows="8"> <?php echo $tagdetailstoprint; ?></textarea></td>
</tr>
<?php
$i++;
}
?>
</table>
<style>
.form-control
{
display:none;
}
</style>
<script type="text/javascript">
$(document).ready(function()
{
$(".edit_tr").click(function()
{
var ID=$(this).attr('id');
$("#details_"+ID).hide();
$("#details_input_"+ID).show();
}).change(function()
{
var ID=$(this).attr('id');
var tagdetailsarea=$("#details_input_"+ID).val();
var dataString = 'printid='+ ID +'&printdetails='+tagdetailsarea;
$("#details_"+ID).html('<img src="load.gif" />');
if(tagdetailsarea.length>0)
{
$.ajax({
type: "POST",
url: "print-tags-edit.php",
data: dataString,
cache: false,
success: function(html)
{
$("#details_"+ID).html(tagdetailsarea);
}
});
}
else
{
alert('You can not Print Blank Data');
}


});
$(".form-control").mouseup(function()
{
return false
});
$(document).mouseup(function()
{
$(".form-control").hide();
$(".text").show();
});
});
</script>

更新 print-tags-edit.php 的文件:

<?php 
if($_POST['printid'])
{
$id=$_POST['printid'];
$details=$_POST['printdetails'];
$sql = "update tagto_print set print_tag_details='$details' where print_tag_id='$id'";
mysql_query($sql);

}
?>

最佳答案

当你打印它时,只需将它放在这个函数中,这将在 php 中打印

nl2br($txt)

如果事情是颠倒的,在将数据写入文件之前先查看源代码
如果找到 br 则将其替换为新行 \n

关于php - Textarea 不使用 ajax 更新换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26773065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com