占位符在IE-9中不起作用,因此我使用以下代码作为占位符.
jQuery(function () { debugger; jQuery.support.placeholder = false; test = document.createElement('input'); if ('placeholder' in test) jQuery.support.placeholder = true; }); // This adds placeholder support to browsers that wouldn't otherwise support it. $(function () { if (!$.support.placeholder) { var active = document.activeElement; $(':text').focus(function () { if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) { $(this).val('').removeClass('hasPlaceholder'); } }).blur(function () { if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) { $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder'); } }); $(':text').blur(); $(active).focus(); $('form:eq(0)').submit(function () { $(':text.hasPlaceholder').val(''); }); } });
解决方法
我想这会对你有所帮助
if ($.browser.msie) { $("input").each(function () { if (IsNull($(this).val()) && $(this).attr("placeholder") != "") { $(this).val($(this).attr("placeholder")).addClass('hasPlaceHolder'); $(this).keypress(function () { if ($(this).hasClass('hasPlaceHolder')) $(this).val("").removeClass('hasPlaceHolder'); }); $(this).blur(function () { if ($(this).val() == "") $(this).val($(this).attr("placeholder")).addClass('hasPlaceHolder'); }); } }); }
原文地址:https://www.jb51.cc/js/156613.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。