0

I need to add an initial text in textarea in two lines enter image description here

and to clear textarea on focus.
I tried to use this code

var startVal = 'Additional info: <br > text text text';
    var messBox = $('.textarea-1').val(startVal);

    messBox.on('focus blur', function(){
        var curVal = $.trim($(this).val());
        if(curVal == startVal) {
        $(this).val('');
        } else if(!curVal){
        $(this).val(startVal);
        }
    });

but it shows <br> tag inside my text and doesn't migrate the second row on new line.

How to make it work?

4

1 回答 1

1

解决方案:使用\n代替<br>

var startVal = "Additional info:\ntext text text";

演示

于 2013-10-26T08:36:12.633 回答