web页面实现emptyText 效果 兼容firefox/google/360

第一步:

$("[name='sql']").attr({"placeholder" : "内
容"}); 

结果显示:内
容

第二步:

<textarea name="sql" id="sql" class="mini-textarea" rows="20" required="true" requiredErrorText="SQL不能为空"  emptyText="aaabb&#10;cccc"></textarea>

这样写,在谷歌、360都可以换行,火狐不行

第三步:

<textarea name="sql" id="sql" class="mini-textarea" rows="20" required="true" requiredErrorText="SQL不能为空"  ></textarea>

 1     var placeholder="SQL查询注意事项:
(1)目前已自动添加了条数限制,最大为1000条,不需要sql添加条数限制;
(2)where 条件中包含时间的,需使用to_date(...)函数进行转换;
(3)使用自定义函数需加别名;
(4)查询结果提示"table or view does not exist"时,需确认数据表是否存在,或者数据源、数据库名是否正确;";
 2     $("[name='sql']").css({"color" : "gray"});
 3     $("[name='sql']").val(placeholder);
 4     $("[name='sql']").focus(function() {
 5         if ($(this).val().contains("SQL查询注意事项:")) {
 6             $(this).val('');
 7             $(this).css({"color" : "black"});
 8         }
 9     });
10 
11     $("[name='sql']").blur(function() {
12         if ($(this).val() == '') {
13             $(this).val(placeholder);
14             $(this).css({"color" : "gray"});
15         }
16     });
View Code

即可。

原文地址:https://www.cnblogs.com/loveok-56/p/6898488.html