如何在IE8和9中支持占位符属性

我有一个小问题,placeholderIE 8-9不支持输入框的属性。


在我的项目(ASP Net)中获得这种支持的最佳方法是什么。我正在使用jQuery。我需要使用其他一些外部工具吗?


是http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html好的解决办法?


MMTTMM
浏览 540回答 3
3回答

绝地无双

在$ .Browser.msie是不是最新的JQuery了...你必须使用$。支持如下所示:&nbsp;<script>&nbsp; &nbsp; &nbsp;(function ($) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$.support.placeholder = ('placeholder' in document.createElement('input'));&nbsp; &nbsp; &nbsp;})(jQuery);&nbsp; &nbsp; &nbsp;//fix for IE7 and IE8&nbsp; &nbsp; &nbsp;$(function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!$.support.placeholder) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$("[placeholder]").focus(function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($(this).val() == $(this).attr("placeholder")) $(this).val("");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}).blur(function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($(this).val() == "") $(this).val($(this).attr("placeholder"));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}).blur();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$("[placeholder]").parents("form").submit(function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(this).find('[placeholder]').each(function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($(this).val() == $(this).attr("placeholder")) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(this).val("");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp;});&nbsp;</script>
打开App,查看更多内容
随时随地看视频慕课网APP