input聚焦palcehoder不显示,失焦如果没有输入值则显示
程序员文章站
2022-04-06 11:39:11
...
需求:input聚焦palcehoder不显示,失焦如果没有输入值则显示(weui为例)
方法:
html
<div class="weui-cell start_address" style="display: none">
<div class="weui-cell__hd"><label for="start_address" class="weui-label start_address_label">出发地:</label></div>
<div class="weui-cell__bd">
<input id="start_address" class="weui-input start_address_input fontColor" type="input" placeholder="手动输入出发地地址">
</div>
</div>
<div class="weui-cell ">
<div class="weui-cell__hd "><label for="end_address" class="weui-label end_address_label">目的地:</label></div>
<div class="weui-cell__bd ">
<input id="end_address" class="weui-input end_address fontColor" type="input" placeholder="手动输入目的地地址">
</div>
</div>
js
//目的地和出发地placeHolder聚焦/失焦得处理
handlePlaceHolder:function () {
this.el.find('.start_address_label,.end_address_label,.start_address_input,.end_address').focus((e)=>{
if ($(e.currentTarget).attr('placeholder')) {
$(e.currentTarget).attr('placeholder','')
}
})
this.el.find('.start_address_label,.end_address_label,.start_address_input,.end_address').blur((e)=>{
if (!$(e.currentTarget).attr('placeholder')) {
let str;
if ($(e.currentTarget).attr('data-name')=='目的地') {
str='手动输入目的地地址'
}
else if ($(e.currentTarget).attr('data-name')=='出发地') {
str='手动输入出发地地址'
}
$(e.currentTarget).attr('placeholder',str)
}
})
}
下一篇: vue默认input获取焦点