jQuery+CSS3搜索框特效,点击输入框显示
JavaScript Code
- <script type="text/javascript">
- function searchToggle(obj, evt){
- var container = $(obj).closest('.search-wrapper');
- if(!container.hasClass('active')){
- container.addClass('active');
- evt.preventDefault();
- }
- else if(container.hasClass('active') && $(obj).closest('.input-holder').length == 0){
- container.removeClass('active');
- // clear input
- container.find('.search-input').val('');
- // clear and hide result container when we press close
- container.find('.result-container').fadeOut(100, function(){$(this).empty();});
- }
- }
- function submitFn(obj, evt){
- value = $(obj).find('.search-input').val().trim();
- _html = "您搜索的关键词: ";
- if(!value.length){
- _html = "关键词不能为空。";
- }
- else{
- _html += "<b>" + value + "</b>";
- }
- $(obj).find('.result-container').html('<span>' + _html + '</span>');
- $(obj).find('.result-container').fadeIn(100);
- evt.preventDefault();
- }
- </script>
XML/HTML Code
- <form onSubmit="submitFn(this, event);">
- <div class="search-wrapper">
- <div class="input-holder">
- <input type="text" class="search-input" placeholder="请输入关键词" />
- <button class="search-icon" onClick="searchToggle(this, event);"><span></span></button>
- </div>
- <span class="close" onClick="searchToggle(this, event);"></span>
- <div class="result-container">
- </div>
- </div>
- </form>
原文地址:http://www.freejs.net/article_biaodan_595.html