ie9不支持placeholder

html:
<Input
    v-model="searchWord"
    placeholder="查找关键词"
    @on-enter="searchTags"
    @on-focus="inputFocus"
    @on-blur="inputBlur">
</Input>
<span class="search-icon" v-if="icon === 'search'" @click="clickSearch"></span>
<span class="clear-icon" v-else @click="clickSearch"></span>

methods {

    // 兼容IE9下的placeholder
placeholderSupport () {
return 'placeholder' in document.createElement('input');
},

    inputFocus () {
this.icon = 'close'
},
inputBlur () {
setTimeout(() => this.icon = 'search', 300)
},
    // 点击图标搜索
clickSearch () {
if (this.icon === 'close') {
this.searchWord = ''
$('span.placeholder').show()
// 重新获取数据
}else {
// 进行搜索
}
},

}


mounted {

    // ie9 placeholder
// 判断浏览器是否支持 placeholder
if(!this.placeholderSupport()){
$("[placeholder]").each(function(){
var _this = $(this);
var left = _this.css("padding-left");
_this.parent().append('<span class="placeholder" data-type="placeholder" style="left: ' +
left + '; position: absolute; top: 10px; left: 5px; color: #ccc;">' +
_this.attr("placeholder") + '</span>');
if(_this.val() != ""){
_this.parent().find("span.placeholder").hide();
}
else{
_this.parent().find("span.placeholder").show();
}
}).off('focus').on("focus", function(){
$(this).parent().find("span.placeholder").hide();
}).off("blur").on("blur", function(){
var _this = $(this);
if(_this.val() != ""){
_this.parent().find("span.placeholder").hide();
}
else{
_this.parent().find("span.placeholder").show();
}
});
// 点击表示placeholder的标签相当于触发input
$("span.placeholder").off('click').on("click", function(){
$(this).hide();
$(this).siblings("[placeholder]").trigger("click");
$(this).siblings("[placeholder]").trigger("focus");
});
}

}

css:  自行定义

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值