开发者

Span content in textarea

<style>    
    .span1{
         left:10px;
     }

    .span2{
         left:20px;
     }
</style>

<span class='span1'> 1 </span> 
<span class='span2'> 2 </span>

I want to display the above content in textarea, in need a regex where I can replace <span> tags with &nbsp; so that the content in the textarea are correctly shown

It is for text editor where i would like to place certain key words automatically aligned. 开发者_StackOverflow社区I am using a textarea in hidden state. When the user alters the code in div it is reflected in to the textarea in the div the code is heighlighting with different colors using css. I want the css tags 1 to be removed and replace 1 10 at the place i wanted in textarea so that when the file is saved, it will be submitted in the correct format.


I am not sure if I understood you well, but correct me if I am wrong. The code uses jQuery:

var shiftStep = 10,
    output = '';

$('span').each(function() {
    var $this = $(this),
        value = $this.text(),
        leftOffset = $this.css('left').slice(0, -2),
        finish = Math.floor(leftOffset / shiftStep);

    for (var i = 0; i < finish; i += 1) {

        /*
         * '&nbsp;' will be displayed as '&nbsp;'
         * in textarea, so use ' ' (space)
         */ 
        output += ' ';
    }

    output += value + '\n';
});

$('#output').val(output);

Additionally, you will have to change your CSS slightly.

The working result: http://jsfiddle.net/xrzNB/1/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜