html重置文本框按钮,html输入框中删除按钮输入出现,不输入隐藏交互实现

$(function(){

var winHeight = $(window).height();

$('.delectIcon').tap(function(){

$(this).parents('.Cformline').find('input').val("");

})

//点击清除按钮清空输入框中的内容

$('.delectIcon').parent('.Ltar').tap(function(){

$(this).parents('.Cformline').find('input').val("");

})

$('input').bind("focus input propertychange",function(){

if($(this).val().length!=0){

var delIcon = $(this).parents('.Cformline').find('.delectIcon');

delIcon.css({'display':'inline-block'});

}else{

$('.delectIcon').hide();

}

})

//点击除了输入框以外的html元素时删除按钮消失

$('body').tap(function(e){

if($(e.target).closest("input").length == 0){

$('.delectIcon').hide();

}

})

//(ios)滑动屏幕时删除按钮消失

$(window).scroll(function () {

if(document.body.scrollTop == 0){

$('.delectIcon').hide();

}

})

//(安卓端)键盘落下时删除按钮消失

$(window).resize(function(){

var thisHeight = $(window).height();

if(winHeight - thisHeight <= 50){

$('.delectIcon').hide();

}else{

if($("input:focus").val() && $("input:focus").val().length > 0){

$('.delectIcon').css({'display':'inline-block'});

}

}

})

})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值