在单击按钮时将textarea的每一行文本显示为div

在单击按钮时将textarea的每一行文本显示为div

本文介绍了在单击按钮时将textarea的每一行文本显示为div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi

I wanna get textarea's each line text into div. Below is my code but problem is that when I'm clicking second time on button then old and new values is being added.

I wanna show only current values on textarea even if i click so many time.

 /* Preview Details */
$('.btn-preview-details').on('click', function(){
    PopupContainer('.modal.preview-details-popup');
    previewDetailsText();
});

/* preview text area's each line */
function previewDetailsText(){
    var getVal = $('#detailText').val();
    if(getVal != ""){
        var getText = getVal.split('\n');
        var items=new Array()
        var counter = 0
        for(var i = 0; i < getText.length; i++){

            /* using lines[i] which will give you each line */

            $('.preview-text').append('<li>'+getText[i]+'</li>');
        }
    }
}

HTML :
<textarea class="span12" name="detailText" id="detailText" rows="6"></textarea>
<button type="button" class="btn btn-inverse btn-preview-details">Preview</button>




谢谢.




Thanking You.

推荐答案






谢谢.




Thanking You.


这篇关于在单击按钮时将textarea的每一行文本显示为div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:51