占位符在IE9中不起作用 [英] placeholder is not working in IE9
问题描述
我是salesforce(SFDC)开发人员。
在我输入框的visualforce页面中,我使用占位符代码。
I am salesforce (SFDC) developer. In my visualforce page for input box I am using placeholder code.
<div class="control-group">
<label class="control-label visible-desktop" for="first_name">First Name</label>
<div class="controls">
<input class="input-block-level" name="First Name" id="first_name" placeholder="First Name" value="" type="text" required="required" autofocus="autofocus" />
</div>
</div>
我在互联网上检查了一些CSS黑客,但我没有找到任何。
我发现了一些javascript hack。
I checked in internet for some CSS hack but I didn't find any. I find some javascript hack.
HTML5占位符jQuery插件
HTML5 Placeholder jQuery Plugin
https://github.com/mathiasbynens/jquery-placeholder
演示&示例
http://mathiasbynens.be/demo/placeholder
但我不想使用jQuery hack或其他东西。
But I don't want to use jQuery hack or something.
推荐答案
由于IE9不支持占位符属性,你可以在Javascript / jQuery中这样做(快速编写,未经测试):
As IE9 doesn't support the placeholder attribute, you can do it in Javascript/jQuery like so (quickly written, not tested):
if(navigator.appVersion.match(/MSIE [\d.]+/)){
var placeholderText = 'Some Placeholder Text';
$('#first_name').val(placeholderText);
$('#first_name').blur(function(){
$(this).val() == '' ? $(this).val(placeholderText) : false;
});
$('#first_name').focus(function(){
$(this).val() == placeholderText ? $(this).val('') : false;
});
}
对模糊事件执行相同操作,然后模仿占位符属性。
Do the same for the blur event too, then that will mimic a placeholder attribute.
好的,重新考虑之后(由于评论)这真的不是最优雅的解决方案(但确实有效),所以我完全不理会这个答案。
Okay, after rethinking this (due to the comment) this is really not the most elegant solution (however it does work), so I would disregard this answer totally.
这篇关于占位符在IE9中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!