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

第一步:css

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

结果显示:内
容数据库

第二步:ide

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

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

第三步:this

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

 1     var placeholder="SQL查询注意事项:\r\n(1)目前已自动添加了条数限制,最大为1000条,不须要sql添加条数限制;\r\n(2)where 条件中包含时间的,需使用to_date(...)函数进行转换;\r\n(3)使用自定义函数需加别名;\r\n(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

便可。code

相关文章
相关标签/搜索