您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在textarea的占位符属性内插入换行符?

在textarea的占位符属性内插入换行符?

您可以做的是将文本添加value,这要注意换行符\n

$('textarea').attr('value', 'This is a line \nthis should be a new line');

然后,您可以将其移除,focus然后将其重新应用(如果为空)blur。像这样

var placeholder = 'This is a line \nthis should be a new line';
$('textarea').attr('value', placeholder);

$('textarea').focus(function(){
    if($(this).val() === placeholder){
        $(this).attr('value', '');
    }
});

$('textarea').blur(function(){
    if($(this).val() ===''){
        $(this).attr('value', placeholder);
    }    
});

不是纯CSS也不 干净, 但是可以解决问题。

其他 2022/1/1 18:15:57 有493人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶