[英]Placeholder internet explorer 11 not showing
I have a problem with placeholders in IE 11 even though it says in compatibility table that IE 11 can show placeholders.我对 IE 11 中的占位符有疑问,尽管它在兼容性表中说 IE 11 可以显示占位符。 I am not talking about focus on input.我不是在谈论关注输入。 There are no placeholders also when I am not focused on input box.当我不关注输入框时,也没有占位符。
IE Version: 11.0.9600浏览器版本:11.0.9600
I have no css applied on the placeholders.我没有在占位符上应用 css。
In other browsers placeholder is showing.在其他浏览器中显示占位符。
I tried also compatibility using meta tags, no change.我也尝试使用元标记的兼容性,没有变化。
<input id="textinput" name="name" type="text" placeholder="Name" class="form-control input-md" /></input>
Okay folks, I just discovered that my lovely company has installed IE 11 but with forced IE 8 view - my god.好的伙计们,我刚刚发现我可爱的公司已经安装了 IE 11,但强制使用 IE 8 视图 - 我的上帝。
whole code in the link链接中的完整代码
$(function(){$("input, textarea").placeholder()
I just answered this on another Stackoverflow question but maybe I can help people in this question too.我刚刚在另一个 Stackoverflow 问题上回答了这个问题,但也许我也可以帮助解决这个问题的人。
I had the same problem and found out that it was the setting of my CSS framework (Foundation) that put a height of 2.4375rem to all inputs... You need to override that!我遇到了同样的问题,发现是我的 CSS 框架(Foundation)的设置为所有输入设置了 2.4375rem 的高度......你需要覆盖它! With something like像这样的东西
[type=color],
[type=date],
[type=datetime-local],
[type=datetime],
[type=email],
[type=month],
[type=number],
[type=password],
[type=search],
[type=tel],
[type=text],
[type=time],
[type=url],
[type=week],
textarea {
height: auto;
}
如果您使用 JavaScript 或普通用户交互专注于输入,则 IE 11 将不会显示占位符。
add below placeholder-label.js as an external js.添加下面的 placeholder-label.js作为外部 js。
( function( $ ) {
var IE10 = !!(navigator && navigator.userAgent && navigator.userAgent.match('MSIE 10'));
var IE11 = !!(navigator && navigator.userAgent && navigator.userAgent.match(/Trident.*rv\:11\./));
var overridePlaceholder = (IE10 || IE11);
$.fn.placeholder_labels = function(options) {
var that = this;
var defaults = {
blurColor : '#aaaaaa',
focusColor : '#bbbbbb',
labelClass : 'placeholder-label'
}
var settings = $.extend({}, defaults, options);
// test if HTML5 placeholder is supported or we do not want to
// override default placeholder behavior; if so, quit
if ('placeholder' in document.createElement('input') && !overridePlaceholder) {
return this;
}
// Go through each input and/or text area and add a placeholder label
// should be envoked as follows
// $("input[placeholder], textarea[placeholder]").placeholder_labels();
this.each(function(){
var $input = $( this );
var placeholder_text = $input.attr( 'placeholder' );
if (overridePlaceholder) $input.attr('placeholder', '');
var line_height = {};
if( !$input.is('textarea') && $input.css('height') != 'auto') {
line_height = { lineHeight: '23px', whiteSpace: 'nowrap' };
//add line height as below if having alignment
//$input.css('height')
}
// create a label and a span within it
var $label = $( '<label></label>' ).addClass(settings.labelClass);
$label.css("width", "100%");
var $span = $( '<span>' + placeholder_text + '</span>' );
$span.appendTo( $label );
// Copy input styles and apply them to the placeholder
// should get it 95% of the way toward looking right
$span.css($.extend({
position:'absolute',
display: 'inline',
float: 'none',
overflow: 'hidden',
textAlign: 'left',
color: settings.blurColor,
cursor: 'text',
paddingTop: $input.css('padding-top'),
paddingRight: $input.css('padding-right'),
paddingBottom: $input.css('padding-bottom'),
paddingLeft: $input.css('padding-left'),
marginTop: $input.css('margin-top'),
marginRight: $input.css('margin-right'),
marginBottom: $input.css('margin-bottom'),
marginLeft: $input.css('margin-left'),
fontSize: $input.css('font-size'),
fontFamily: $input.css('font-family'),
fontStyle: $input.css('font-style'),
fontWeight: $input.css('font-weight'),
textTransform: $input.css('text-transform'),
backgroundColor: 'transparent',
zIndex: 99
}, line_height));
$('#typefi-btn-clear-filter').insertAfter('#typefi-files-search-input');
// the label surrounds the input
$label.insertBefore( $input ).append( $input );
// try getting the input's size even if it is hidden
var w = $input.width(),
h = $input.height();
// test for the case of the input being hidden
if ( !w || !h ) {
// get dimensions by cloning the input and grabbing height and width
var $clone = $input.clone().appendTo( 'body' ).css({
position : 'absolute',
visibility : 'hidden',
display : 'block'
});
// fetch the correct size (hopefully)
w = $clone.width();
h = $clone.height();
$clone.remove();
}
// if the input is hidden or shown, so should the placeholder be
$input.on('hide', function() {
$span.hide();
});
// when showing, ensure the text is the right size
$input.on('show', function(){
$span.show().css({
width:$input.width()+'px',
height:$input.height()+'px'
});
});
/* If the input is starting out hidden or there is a default value in
* the input already, hide the placeholder
*/
if ( !$input.is(':visible') || $input.val().length ) {
$span.hide();
}
/* Show the placeholder untill a key is pressed in the field
* restore the placeholder if the field is blank.
*/
$input
.on("keydown keyup", function() {
if ( $(this).val() === "" ) {
$span.show();
} else {
$span.hide();
}
})
.focus( function() {
$span
.addClass( "input-selected" )
.css('color', settings.focusColor);
})
.blur( function() {
$span
.removeClass( "input-selected" )
.css('color', settings.blurColor);
});
// If the placeholder is focused, send focus to the input
$span.focus( function() {
$input.focus();
});
// If autofocus, refocus input
if($input.attr("autofocus")){
$input.focus();
}
});
// override jQuery.hide() to trigger the 'hide' event
var hide = $.fn.hide;
$.fn.hide = function() {
this.trigger('hide');
return hide.apply(this, arguments);
};
// override jQuery.show() to trigger the 'show' event
var show = $.fn.show;
$.fn.show = function() {
this.trigger('show');
return show.apply(this, arguments);
};
return that;
};
})( jQuery );
Then Link js in HTML as below.然后如下链接HTML中的js。
<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js\"></script>
<script src="/js/placeholder-label.js"></script>
<script>
$( function() {
$("input[placeholder], textarea[placeholder]").placeholder_labels();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.