[英]JavaScript textarea character counter inserting tab
When users on my site go to set their bio for their profile, there is a Javascript character counter to show how many characters they have remaining. 当我网站上的用户去设置个人资料作为个人资料时,就会有一个Javascript字符计数器显示剩余的字符数。
When they go to write a new bio or edit their current one, inside the tags their current bio is echo'd in PHP from the database. 当他们去写一个新的履历或编辑他们当前的履历时,在标签内,他们当前的履历将在PHP中从数据库中回显。 Here's the code
这是代码
<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>
When they hit the submit button in the form, it saves the bio successfully and everything, but now it shows their bio with the <?php if(strlen($row[20])!=0) {echo $row[20];}?>
with loads of tabs around it. 当他们单击表单中的“提交”按钮时,它成功保存了个人简介以及所有内容,但是现在它显示了
<?php if(strlen($row[20])!=0) {echo $row[20];}?>
周围带有许多标签。
So, for example 因此,例如
Hello, my name is James
你好,我叫詹姆斯
Would become 会成为
Hello, my name is James
It's definitely something wrong with the script, because it doesn't save these spaces/tabs to the database. 该脚本肯定有问题,因为它不会将这些空格/制表符保存到数据库中。
You're inserting the tabs yourself. 您要自己插入标签。 ANYTHING between the
<textarea>
and </textarea>
becomes part of the displayed editable text. <textarea>
和</textarea>
之间的任何内容都将成为显示的可编辑文本的一部分。 Your code should be 您的代码应为
<textarea>$text_to_insert</textarea>
Note that lack of any whitespace between the tags and the inserted variable/text.Your version is 注意标签和插入的变量/文本之间没有空格,您的版本是
<textarea>[linebreak]
[tab][tab][tab]$text_to_insert[linebreak]
</textarea>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.