JavaScript实现输入框与清空按钮联动效果
废话不多说了,直接给大家贴关键代码了,具体代码如下所示:
<!DOCTYPE html><html><head><metacharset="UTF-8"><title>输入框清空按钮</title><scriptsrc="js/jquery1.8.3.min.js"></script><script>/** * 校验当前输入框的值,如果不为空显示清空按钮 * @param element */functioncheckInput(element){var value = $(element).val(); if(value!=null&&''!=value) $(element).parent().parent().children().children('.button').removeClass('none'); else $(element).parent().parent().children().children('.button').addClass('none'); } /** * 清空输入框内容 * @param element */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:1px solid red; border-radius:5px; }</style></head><body><div><div><inputtype="text"placeholder="输入试试看"onkeyup="checkInput(this);" > </div><divclass="height-20" ></div><div> <aclass="none button"onclick="clearInput(this);" >clear input</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); }); });
相关推荐
guangmingsky 2020-07-27
坚持着执着 2020-07-16
delmarks 2020-06-07
niehanmin 2020-05-28
ITstudied 2020-05-17
chenjinlong 2020-05-16
Richardxx 2020-05-16
e度空间 2020-05-07
jianghero 2020-05-03
郴州小程序 2020-02-19
Feastaw 2020-01-18
haohong 2020-01-17
起点 2019-12-11
虫二在路上 2014-06-05
CaiKanXP 2019-10-25
82473264 2014-07-01
STPace 2014-11-10