占位符IE9-Javascript未在IE9中执行 [英] Placeholder IE9 - Javascript not executed in IE9
问题描述
我目前正在Drupal中开发一个网站,并且使用Javascript替换了IE8-9中的占位符属性.这是代码:
I'm currently developping a website in Drupal and i used a Javascript to replace the placeholder property in IE8-9. Here's the code :
$('input[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur();
但是它似乎没有被执行.导航器没有进入功能内部.当我通过控制台启动它时,它工作正常. 有谁知道如何解决它?
But it doesn't seem to be executed. The navigator doesn't go inside the function. When i launch it trough the console it works fine. Does anyone have an idea of how to fix it ?
即使放置了正确的选择器,它仍然无法正常工作 非常感谢
EDIT : Even when putting the right selector, it's still not working Thanks a lot
推荐答案
placeholder
是某些html元素(输入)的属性,您必须添加与给定属性匹配的选择器:
The placeholder
is an attribute of some html elements (inputs), you have to add a selector matching the given attribute:
$('*[placeholder]').focus(function() { //Or input[placeholder]
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur();
这篇关于占位符IE9-Javascript未在IE9中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!