思路:利用文本框的聚焦和失焦事件

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>    

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
相关资源
相似解决方案