问题
I've tried using two different jquery plugins to get placeholders to work in ie9, Andrew Jones one and Mathias Bynens one.
Unfortunately, both of them are giving me the same set of issues, that for the life of me I cannot figure out. The first issue is, every now and then in the JS console I get the following error :
SCRIPT438: Object doesn't support property or method 'placeholder'
...which is as if the script didn't load, even though it has. Its usually the 50/50 chance of that error showing up when I refresh the page. The next issue I'm encountering is that sometimes the placeholders won't even show up, but then when I click the input field and then click somewhere else the placeholder text will finally appear.
This is being used in a rails app. I'm using placeholder like so, at the top of main.js document.ready()
if (navigator.userAgent.match(/MSIE\s(?!10.0)/)) {
$(":input[placeholder]").placeholder();
}
And I am including the script in layouts/application.html.erb
like so:
<%=stylesheet_link_tag "normalize"%>
<%=stylesheet_link_tag "main"%>
<%=stylesheet_link_tag "r"%>
<%=stylesheet_link_tag "1140"%>
<%=stylesheet_link_tag "ie"%>
<%=stylesheet_link_tag "jquery.placeholder.min"%>
<%=javascript_include_tag "vendor/jquery-1.8.0.min.js"%>
<%=javascript_include_tag "vendor/modernizr-2.6.1.min.js"%>
<%=javascript_include_tag "vendor/css3-mediaqueries.js"%>
<%=javascript_include_tag "vendor/jquery.fitvids.js"%>
<%=javascript_include_tag "plugins.js"%>
<%=javascript_include_tag "rails.js"%>
<%=javascript_include_tag "jquery.placeholder.min.js"%>
<%=javascript_include_tag "main.js.erb"%>
<%=csrf_meta_tag %>
Any help on this issue would be greatly appreciated.
来源:https://stackoverflow.com/questions/15413095/issues-with-jquery-placeholder-plugin