JavaScript实现输入框与清空按钮联动效果
废话不多说了,直接给大家贴关键代码了,具体代码如下所示:
<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>输入框清空按钮</title><scriptsrc="js/jquery1.8.3.min.js"></script><script>/**
*校验当前输入框的值,如果不为空显示清空按钮
*@paramelement
*/functioncheckInput(element){varvalue=$(element).val();
if(value!=null&&''!=value)
$(element).parent().parent().children().children('.button').removeClass('none');
else
$(element).parent().parent().children().children('.button').addClass('none');
}
/**
*清空输入框内容
*@paramelement
*/functionclearInput(element){
$(element).parent().parent().children().children('input').val('');
$(element).addClass('none');
}
</script><style>.none{
display:none;
}.height-20{
height:20px;;}.button{
color:red;
font-size:18px;
width:100px;
height:18px;;border:1pxsolidred;
border-radius:5px;
}</style></head><body><div><div><inputtype="text"placeholder="输入试试看"onkeyup="checkInput(this);">
</div><divclass="height-20"></div><div>
<aclass="nonebutton"onclick="clearInput(this);">clearinput</a></div></div></body>
</html>
').addClass('pre-numbering').hide();$(this).addClass('has-numbering').parent().append($numbering);for(i=1;i<=lines;i++)
{$numbering.append($('
').text(i));};$numbering.fadeIn(1700);});});
以上所述是小编给大家介绍的JavaScript实现输入框与清空按钮联动效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!