文章的关键字获得焦点显示提示内容,关键字失去焦点隐藏提示内容
2012-04-05 20:16
477 查看
一般文章中都会有些术语或者概念较深刻的词,大家看不懂。很多人都会选择给这些关键字加个超链接,跳到另一个页面查看他的内容,从SEO的角度看有利,但这样其实很不友好。本文教大家一个方法:给超链接加个注释信息,鼠标获得焦点显示提示信息,鼠标失去焦点,隐藏该提示信息。很方便的喔~
以下是脚本内容:
<script type="text/javascript">
//显示提示内容
</script>
然后为文章的超链接,调用相关的函数就可以实现了:
<a onmouseout="hidenHelpTip(event);"
onmouseover="showHelpTip(event, 'Normally we would ship out PAL or NTSC version camera according to different countries. For example, we would ship out PAL camera to United Kingdom, Australia, German, France and etc; we would
ship out NTSC camera to United States, Canada and etc. If you want to specify PAL or NTSC camera, you could leave us a note to “Order Instructions/Comments” when checking out.'); return false;" class="HelpLink">PAL/NTSC</a>
以下是脚本内容:
<script type="text/javascript">
//显示提示内容
function showHelpTip(e, sHtml, bHideSelects) { // find anchor element var el = e.target || e.srcElement; while (el.tagName != "A") el = el.parentNode; // is there already a tooltip? If so, remove it if (el._helpTip) { helpTipHandler.hideHelpTip(el); } helpTipHandler.hideSelects = Boolean(bHideSelects); // create element and insert last into the body helpTipHandler.createHelpTip(el, sHtml); // position tooltip helpTipHandler.positionToolTip(e); // add a listener to the blur event. // When blurred remove tooltip and restore anchor el.onblur = helpTipHandler.anchorBlur; el.onkeydown = helpTipHandler.anchorKeyDown; } //隐藏提示内容 function hidenHelpTip(e) { // find anchor element var el = e.target || e.srcElement; while (el.tagName != "A") el = el.parentNode; // is there already a tooltip? If so, remove it if (el._helpTip) { helpTipHandler.hideHelpTip(el); } } var helpTipHandler = { hideSelects: false, helpTip: null, showSelects: function (bVisible) { if (!this.hideSelects) return; // only IE actually do something in here var selects = []; if (document.all) selects = document.all.tags("SELECT"); var l = selects.length; for (var i = 0; i < l; i++) selects[i].runtimeStyle.visibility = bVisible ? "" : "hidden"; }, create: function () { var d = document.createElement("DIV"); d.className = "help-tooltip"; d.onmousedown = this.helpTipMouseDown; d.onmouseup = this.helpTipMouseUp; document.body.appendChild(d); this.helpTip = d; }, createHelpTip: function (el, sHtml) { if (this.helpTip == null) { this.create(); } var d = this.helpTip; d.innerHTML = sHtml; d._boundAnchor = el; el._helpTip = d; return d; }, // Allow clicks on A elements inside tooltip helpTipMouseDown: function (e) { var d = this; var el = d._boundAnchor; if (!e) e = event; var t = e.target || e.srcElement; while (t.tagName != "A" && t != d) t = t.parentNode; if (t == d) return; el._onblur = el.onblur; el.onblur = null; }, helpTipMouseUp: function () { var d = this; var el = d._boundAnchor; el.onblur = el._onblur; el._onblur = null; el.focus(); }, anchorBlur: function (e) { var el = this; helpTipHandler.hideHelpTip(el); }, anchorKeyDown: function (e) { if (!e) e = window.event if (e.keyCode == 27) { // ESC helpTipHandler.hideHelpTip(this); } }, removeHelpTip: function (d) { d._boundAnchor = null; d.style.filter = "none"; d.innerHTML = ""; d.onmousedown = null; d.onmouseup = null; d.parentNode.removeChild(d); //d.style.display = "none"; }, hideHelpTip: function (el) { var d = el._helpTip; /* Mozilla (1.2+) starts a selection session when moved and this destroys the mouse events until reloaded d.style.top = -el.offsetHeight - 100 + "px"; */ d.style.visibility = "hidden"; //d._boundAnchor = null; el.onblur = null; el._onblur = null; el._helpTip = null; el.onkeydown = null; this.showSelects(true); }, positionToolTip: function (e) { this.showSelects(false); var scroll = this.getScroll(); var d = this.helpTip; // width if (d.offsetWidth >= scroll.width) d.style.width = scroll.width - 10 + "px"; else d.style.width = ""; // left if (e.clientX > scroll.width - d.offsetWidth) d.style.left = scroll.width - d.offsetWidth + scroll.left + "px"; else d.style.left = e.clientX - 2 + scroll.left + "px"; // top if (e.clientY + d.offsetHeight + 18 < scroll.height) d.style.top = e.clientY + 18 + scroll.top + "px"; else if (e.clientY - d.offsetHeight > 0) d.style.top = e.clientY + scroll.top - d.offsetHeight + "px"; else d.style.top = scroll.top + 5 + "px"; d.style.visibility = "visible"; }, // returns the scroll left and top for the browser viewport. getScroll: function () { if (document.all && typeof document.body.scrollTop != "undefined") { // IE model var ieBox = document.compatMode != "CSS1Compat"; var cont = ieBox ? document.body : document.documentElement; return { left: cont.scrollLeft, top: cont.scrollTop, width: cont.clientWidth, height: cont.clientHeight }; } else { return { left: window.pageXOffset, top: window.pageYOffset, width: window.innerWidth, height: window.innerHeight }; } } };
</script>
然后为文章的超链接,调用相关的函数就可以实现了:
<a onmouseout="hidenHelpTip(event);"
onmouseover="showHelpTip(event, 'Normally we would ship out PAL or NTSC version camera according to different countries. For example, we would ship out PAL camera to United Kingdom, Australia, German, France and etc; we would
ship out NTSC camera to United States, Canada and etc. If you want to specify PAL or NTSC camera, you could leave us a note to “Order Instructions/Comments” when checking out.'); return false;" class="HelpLink">PAL/NTSC</a>
相关文章推荐
- 文本框内默认提示————请输入用户姓名(字体灰色),要求: (1)当文本框获得焦点时,默认提示消失 (2)当文本框失去焦点时,如果没有输入新内容,那么则显示原来的灰色字体内容; 如果有新内容输入则判断,如果长度小于10,则提示“姓名长度应该大于10个字符”
- 输入框的提示信息(获得焦点和失去焦点时显示提示信息)
- input 输入框获得/失去焦点时隐藏/显示文字
- input 输入框获得/失去焦点时隐藏/显示文字(jquery版)
- 单击文本框显示隐藏提示文本,失去焦点时再显示提示文本
- Android 重写EditText,失去焦点超出控件宽度部分三个点表示,获得焦点显示原来内容
- input 输入框获得/失去焦点时隐藏/显示文字(jquery版)
- input 输入框获得/失去焦点时隐藏/显示文字
- input 输入框获得/失去焦点时隐藏/显示文字
- 我的Web学习之路1——input,textarea获得/失去焦点时隐藏/显示文字
- 文本框获得焦点后文本框内的提示文本消失 失去焦点后如果没有输入再显示提示 转
- JQ 搜索框获得焦点,和是失去焦点,默认提示显示与消失
- input 输入框获得/失去焦点时隐藏/显示文字(jquery版)
- 文本框获得焦点后文本框内的提示文本消失 失去焦点后如果没有输入再显示提示
- 键盘显示时Editext获取焦点,键盘隐藏时失去焦点
- input获取焦点时候value值隐藏,失去焦点的时候显示
- 一个列用render渲染的时候,如果列宽度不够,内容多出的部分会被隐藏,无法显示。这时需要一个鼠标滑过提示全部内容的tip功能。
- js:页面多处输入只使用一个验证码/获得焦点显示/onblur隐藏实现
- 织梦dedecms后台发布文章提示“标题不能为空”,编辑器内容无法显示中文
- 文本框提示样式,鼠标点击获得焦点时提示内容消失