jQuery实现点击文本框弹出热门标签的提示效果


Posted in Javascript onNovember 17, 2013
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>jQuery实现点击文本框弹出热门标签的提示示例_网页代码站</title> 
<style type="text/css"> 
body { 
font-size:12px;font-family:Arial; 
} 
#m_tagsItem { 
background:#fff; 
position:absolute; 
top:0px; 
left:0px; 
overflow:hidden; 
width:590px; 
*width:561px; 
width:561px\9; 
padding:10px; 
border:1px solid #ccc; 
z-index:1000; 
display:none; 
} 
#m_tagsItem p { 
text-align:left; 
line-height:22px; 
padding:2px 0; 
margin:0; 
border:0; 
} 
#m_tagsItem span { 
font-weight:bold; 
} 
#m_tagsItem a { 
margin:0 5px; 
} 
.m_tagsname { 
color:#999; 
vertical-align:middle; 
font-size:12px; 
text-indent:3px; 
line-height:20px; 
} 
#tagClose { 
font-size:12px; 
color:#888; 
cursor:pointer; 
position:absolute; 
top:2px; 
right:2px; 
} 
</style> 
<script src="http://www.webdm.cn/themes/script/jquery.js"></script> 
<script language="javascript"> 
(function ($) { 
$.fn.bgIframe = $.fn.bgiframe = function (s) { 
if ($.browser.msie && /6.0/.test(navigator.userAgent)) { 
s = $.extend({ 
top: 'auto', // auto == .currentStyle.borderTopWidth 
left: 'auto', // auto == .currentStyle.borderLeftWidth 
width: 'auto', // auto == offsetWidth 
height: 'auto', // auto == offsetHeight 
opacity: true, 
src: 'javascript:false;' 
}, s || {}); 
var prop = function (n) { return n && n.constructor == Number ? n + 'px' : n; }, 
html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="' + s.src + '"' + 
'style="display:block;position:absolute;z-index:-1;' + 
(s.opacity !== false ? 'filter:Alpha(Opacity=\'0\');' : '') + 
'top:' + (s.top == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')' : prop(s.top)) + ';' + 
'left:' + (s.left == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')' : prop(s.left)) + ';' + 
'width:' + (s.width == 'auto' ? 'expression(this.parentNode.offsetWidth+\'px\')' : prop(s.width)) + ';' + 
'height:' + (s.height == 'auto' ? 'expression(this.parentNode.offsetHeight+\'px\')' : prop(s.height)) + ';' + 
'"/>'; 
return this.each(function () { 
if ($('> iframe.bgiframe', this).length == 0) 
this.insertBefore(document.createElement(html), this.firstChild); 
}); 
} 
return this; 
}; 
})(jQuery); 
jQuery.fn.selectCity = function (targetId) { 
var _seft = this; 
var targetId = $(targetId); 
this.click(function () { 
var A_top = $(this).offset().top + $(this).outerHeight(true); // 1 
var A_left = $(this).offset().left; 
targetId.bgiframe(); 
targetId.show().css({ "position": "absolute", "top": A_top + "px", "left": A_left + "px" }); 
}); 
targetId.find("#tagClose").click(function () { 
targetId.hide(); 
}); 
$(document).click(function (event) { 
if (event.target.id != _seft.selector.substring(1)) { 
targetId.hide(); 
} 
}); 
targetId.click(function (e) { 
e.stopPropagation(); // 2 
}); 
return this; 
} 
$(function () { 
$("#selecttags").selectCity("#m_tagsItem"); 
}); 
//为文本域连续赋值 
function checktag(o) { 
var tagid = function (id) { return document.getElementById(id); } 
var tags = []; //存放标签,避免重复加入 
var tagidSPLITCHAR = ' '; //设定分隔符,根据程序需求可改 
var d = tagid('selecttags'); 
if (d.value) 
tags = d.value.split(tagidSPLITCHAR); 
var v = o.innerHTML; //如果tag有别的值或者别的非innerHTML里体现的内容 
var s = tagidSPLITCHAR + tags.join(tagidSPLITCHAR) + tagidSPLITCHAR 
if (!new RegExp(tagidSPLITCHAR + v + tagidSPLITCHAR, 'g').test(s)) { 
s += v; 
} 
s = s.replace(new RegExp("(^" + tagidSPLITCHAR + "*|" + tagidSPLITCHAR + "*tagid)", "g"), ''); 
d.value = s; 
tags = s.split(tagidSPLITCHAR); 
} 
</script> 
</head> 
<body> 
如果没有出现提示框请刷新一下页面再试~ 
<input type="text" id="selecttags" name="m_tagsname" class="m_tagsname" style="width: 577px" 
value="点击查看热门标签和您曾经使用过的标签" onclick="if(this.value=='点击查看热门标签和您曾经使用过的标签'){this.value='';this.className='m_tagsname'}"> 
<div id="m_tagsItem" style="display: none"> 
<div id="tagClose"> 
关闭</div> 
<p> 
<span>温馨提示:</span>标签间请用“空格”、“逗号”或“分号”隔开,用简练的词语概括您的博文内容。</p> 
<p> 
<span>热门标签:</span><a href="javascript:void(0)" onclick="checktag(this)">彩妆</a><a 
href="javascript:void(0)" onclick="checktag(this)">美发</a><a href="javascript:void(0)" 
onclick="checktag(this)">美优博客</a><a href="javascript:void(0)" onclick="checktag(this)">aaa</a><a 
href="javascript:void(0)" onclick="checktag(this)">bbb</a><a href="javascript:void(0)" 
onclick="checktag(this)">天堂</a><a href="javascript:void(0)" onclick="checktag(this)">eee</a><a 
href="javascript:void(0)" onclick="checktag(this)">fff</a><a href="javascript:void(0)" 
onclick="checktag(this)">ggg</a></p> 
<p> 
<span>您使用过的标签:</span><a href="javascript:void(0)" onclick="checktag(this)">软件</a><a 
href="javascript:void(0)" onclick="checktag(this)">Delphi</a><a href="javascript:void(0)" 
onclick="checktag(this)">博客</a><a href="javascript:void(0)" onclick="checktag(this)">源码</a><a 
href="javascript:void(0)" onclick="checktag(this)">彩妆</a><a href="javascript:void(0)" 
onclick="checktag(this)">google</a><a href="javascript:void(0)" onclick="checktag(this)">新浪</a></p> 
</div> 
<br /> 
<p> 
<a href="http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!</p> 
</body> </html>
Javascript 相关文章推荐
JQuery 选择器、过滤器介绍
Feb 14 Javascript
jQuery教程 $()包装函数来实现数组元素分页效果
Aug 13 Javascript
JQuery实现点击div以外的位置隐藏该div窗口
Sep 13 Javascript
PHPExcel中的一些常用方法汇总
Jan 23 Javascript
jQuery图片轮播插件——前端开发必看
May 31 Javascript
基于javascript实现最简单选项卡切换
Feb 01 Javascript
Vue+axios 实现http拦截及路由拦截实例
Apr 25 Javascript
vue-resource 拦截器(interceptor)的使用详解
Jul 04 Javascript
AngularJS service之select下拉菜单效果
Jul 28 Javascript
详解vue-cli项目中的proxyTable跨域问题小结
Feb 09 Javascript
Vue中的v-for指令不起效果的解决方法
Sep 27 Javascript
简单了解vue中的v-if和v-show的区别
Oct 08 Javascript
ExtJS[Desktop]实现图标换行示例代码
Nov 17 #Javascript
javascript:void(0)是什么意思示例介绍
Nov 17 #Javascript
巧用js提交表单轻松解决一个页面有多个提交按钮
Nov 17 #Javascript
setInterval()和setTimeout()的用法和区别示例介绍
Nov 17 #Javascript
js用正则表达式来验证表单(比较齐全的资源)
Nov 17 #Javascript
jquery在项目中做复选框时遇到的一些问题笔记
Nov 17 #Javascript
jQuery学习之prop和attr的区别示例介绍
Nov 15 #Javascript
You might like
日本因肺炎疫情影响,这几部动漫推延播放!
2020/03/03 日漫
PHP脚本的10个技巧(8)
2006/10/09 PHP
数据库的日期格式转换
2006/10/09 PHP
CodeIgniter使用smtp服务发送html邮件的方法
2015/06/10 PHP
laravel unique验证、确认密码confirmed验证以及密码修改验证的方法
2019/10/16 PHP
Javascript 实现复制(Copy)动作方法大全
2014/06/20 Javascript
原生的html元素选择器类似jquery选择器
2014/10/15 Javascript
JavaScript中的some()方法使用详解
2015/06/09 Javascript
jQuery结合AJAX之在页面滚动时从服务器加载数据
2015/06/30 Javascript
JavaScript编程的单例设计模讲解
2015/11/10 Javascript
jQuery实现简单的DIV拖动效果
2016/02/19 Javascript
js中对象和面向对象与Json介绍
2019/01/21 Javascript
浅谈Vue的响应式原理
2019/05/30 Javascript
node解析修改nginx配置文件操作实例分析
2019/11/06 Javascript
怎么理解wx.navigateTo的events参数使用详情
2020/05/18 Javascript
webpack+vue-cil 中proxyTable配置接口地址代理操作
2020/07/18 Javascript
原生JS实现相邻月份日历
2020/10/13 Javascript
[35:44]2014 DOTA2华西杯精英邀请赛 5 24 iG VS VG
2014/05/26 DOTA
python操作ie登陆土豆网的方法
2015/05/09 Python
Python多线程经典问题之乘客做公交车算法实例
2017/03/22 Python
python 实时得到cpu和内存的使用情况方法
2018/06/11 Python
Python Tornado实现WEB服务器Socket服务器共存并实现交互的方法
2020/05/26 Python
python中字符串的编码与解码详析
2020/12/03 Python
7款设计巧妙的css3飘带状3D立体效果的导航菜单和表单窗口
2013/02/04 HTML / CSS
捷克电器和DJ设备网上商店:Electronic-star
2017/07/18 全球购物
英国网上电器商店:Electricshop
2020/03/15 全球购物
Yahoo-PHP面试题1
2016/07/20 面试题
中专生学习生活的自我评价分享
2013/10/27 职场文书
领导检查欢迎词
2014/01/14 职场文书
给校长的建议书
2014/03/12 职场文书
初三新学期计划书
2014/05/03 职场文书
党的群众路线教育实践活动个人对照检查材料(医生)
2014/11/05 职场文书
股权转让协议范本
2014/12/07 职场文书
公文写作指导之倡议书!
2019/07/03 职场文书
Windows环境下实现批量执行Sql文件
2021/10/05 SQL Server
浅析Python OpenCV三种滤镜效果
2022/04/11 Python