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

2020-05-23 06:22:32易采站长站整理

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