dongxi5494 2016-01-26 12:28
浏览 33
已采纳

每55个字符后插入一个Break

I want to insert a line Break after every 55 characters i have made a jquery script but it doesn't work can some one please point me in the right direction

Jquery.js

$(document).ready(function() {
    $('#text_comment').text($(this).val().replace(/([\s\S]{55})/g, '$1<br />'));

});

Index.php

<input type="text" class="comment" id="text_comment"autocomplete="off"time_date="<?php echo $date_shared;?>" 
    username="<?php echo $comment_username;?>"post_id="<?php echo $shared_id2; ?>"placeholder="Write a Comment"/>
  • 写回答

2条回答 默认 最新

  • doushichun9409 2016-01-26 12:35
    关注

    Line-breaks are automatically removed from inputs with a type of text.

    text: A single-line text field; line-breaks are automatically removed from the input value.

    You can use a textarea to display the line breaks:

    var myString = '1234567890';
    myString = myString.replace(/.{1,2}/g, "$&
    "); //replace 2 with 55 for your example
    
    document.getElementById('text').value = myString; // :(
    document.getElementById('textarea').value = myString; // :)
    <input type="text" id="text"> <-- line-breaks automatically removed
    <br>
    <textarea id="textarea" rows="7"></textarea>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题