×

用JS实现(textarea)placeholder自动换行

作者:天空2017.05.08来源:Web前端之家浏览:15191评论:0
关键词:placeholder

用JS实现(textarea)placeholder自动换行。思路:利用文本框的聚焦和失焦事件

1、HTML结构

<textarea id="text1"></textarea>

2、js方法

<script>
 var placeholder = '第一行文本提示\n第二行文本提示\n第三行文本提示';
 $('#text1').val(placeholder);
 $('#text1').focus(function() {
 if ($(this).val() == placeholder) {
  $(this).val('');
 }
 });
 $('#text1').blur(function() {
   if ($(this).val() == '') {
   $(this).val(placeholder);
   }
 });
</script>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/biji99.html

网友评论文明上网理性发言 已有0人参与

发表评论: