当我网站上的用户为他们的个人资料设置个人简介时,有一个 Javascript 字符计数器可以显示他们还剩多少个字符。
当他们去编写新的简介或编辑当前的简介时,在标签内,他们当前的简介会从数据库中以 PHP 进行回显。这是代码
<script>
$(document).ready(function() {
var text_max = 300;
$('#textarea_feedback').html(text_max + ' characters remaining');
$('#textarea').keyup(function() {
var text_length = $('#textarea').val().length;
var text_remaining = text_max - text_length;
$('#textarea_feedback').html(text_remaining + ' characters remaining');
});
});
</script>
<form action="profile_edit_bio.php" method="post">
<textarea id="textarea" name="bio" class="input-xxlarge" maxlength="300" placeholder="Update your bio! This should be a short paragraph explaining why you're awesome. (Max characters 300)">
<?php if(strlen($row[20])!=0) {echo $row[20];}?>
</textarea>
<div id="textarea_feedback">
If you're seeing this message, please <a href="mailto:support@jaycraft.co">contact support</a>
</div>
<button type="submit" class="btn btn-info">Update bio</button>
</form>
当他们点击表单中的提交按钮时,它成功保存了个人简介和所有内容,但现在它显示了他们的个人简介 <?php if(strlen($row[20])!=0) {echo $row[20];}?>
周围有很多选项卡。
所以,例如
Hello, my name is James
会变成
Hello, my name is James
这肯定是脚本有问题,因为它没有将这些空格/制表符保存到数据库中。
最佳答案
您自己插入标签。 <textarea>
之间的任何内容和</textarea>
成为显示的可编辑文本的一部分。你的代码应该是
<textarea>$text_to_insert</textarea>
请注意,标签和插入的变量/文本之间没有任何空格。您的版本是
<textarea>[linebreak]
[tab][tab][tab]$text_to_insert[linebreak]
</textarea>
关于php - JavaScript文本区域字符计数器插入选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16245825/