我使用mathiasbynens/jquery-placeholder,並且所有版本的瀏覽器對我來說都非常好,因爲我們大多數客戶使用IE7,8。HTML佔位符不會出現在屏蔽的輸入類型上
但像往常一樣在Internet Explorer中存在問題。我有一個輸入類型,正是它被屏蔽的電話號碼,當我關閉該字段佔位符的掩蔽時出現在IE中,否則它不會出現。我怎樣才能解決它在一個有面具的元素上工作。
這裏是代碼:
<input type="text" name="phone_number" id="phone_number_btd" value="<?php echo $phone_number; ?>" placeholder="Phone Number"/>
$("#phone_number_btd").mask("(999) 999-9999? x9999");
及以下代碼來調用一個佔位符的功能:
(jQuery)('[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();
你能提供一個[jsFiddle](http://jsfiddle.net)這個問題嗎? –
不幸的是,這是困難的,因爲我需要包括很多文件,所以我找到了解決方案。這不是最好的方式,但它的工作原理。如果瀏覽器是Internet Explorer,我會忽略屏蔽。 – user2834820