jQuery实现点击文本框弹出热门标签的提示效果 - Web前端
作者:98wpeu发布时间:2026-07-04分类:网页前端技术浏览:254
导读:复制代码代码如下:<!DOCtypehtmlPUBLIC"-//W3C//DTDxhtml1.0Transitional//EN""http://www.w3....
复制代码 代码如下:
<!DOCtypehtml 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 || {});
varprop = 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>
<!DOCtypehtml 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 || {});
varprop = 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>
相关推荐
- 加速网页索引及其 SEO 效果的 10 种方法 - Web前端
- 微信小程序怎么实现分享成功?分享效果还能更出彩? - Web前端
- 微信小程序开发者工具提示error fail to open ide该怎么解决? - Web前端
- 什么是HTML5语义化标签?一篇完整指南帮你搞懂! - Web前端
- jquery.cvtooltip.js 基于jquery的气泡提示插件 - Web前端
- jQuery 文本框模拟下拉列表效果 - Web前端
- 基于jquery的手风琴图片展示效果实现方法 - Web前端
- jQuery实现数字加减效果汇总 - Web前端
- JQuery表格拖动调整列宽效果(自己动手写的) - Web前端
- jquery实现当滑动到一定位置时固定效果 - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 4【第六章】Foundation之按钮和下拉功能 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 9jQuery编写widget的一些技巧分享 - Web前端
- 最近发表
-
- WordPress 应用:如何修改模版头部文件中的 wp_head() - Web前端
- SEO 优化:YouTube SEO Plugin 提升影片流量 - Web前端
- 使用 React 服务器组件在 Next.js 13 中进行国际化 - Web前端
- 3 个意想不到的技术 SEO 问题示例(以及如何解决它们) - Web前端
- Vue 技术专题:Suspense、路由模式与单元测试实践 - Web前端
- 如何防止 WordPress SQL 注入攻击? - Web前端
- SEO 优化:如何围绕技术SEO框架以构建和制定策略? - Web前端
- SEO优化:YouTube SEO 关键词研究工具 - Web前端
- 2025 年帮助代理机构提升客户业绩的 14 款最佳 SEO 工具 - Web前端
- 客户端:服务器之间设置本地 DNS 服务器 - Web前端


