Jquery 文本切换
Jquery text toggle
我正在尝试进行jquery文本切换。如果将鼠标悬停在元素上,则文本将显示在其旁边,反之亦然,当您离开元素区域时,文本将消失。
我的代码还不能工作。另外,我想为不同的链接包含不同的文本。如果有更简单的方法,请提出建议。
.HTML
<div id="container"></div>
<a href="#" id="ovr">clickclickclick</a>
.JS
$("#ovr").mouseenter(function() {
$(#container).html("wazaap");
}).mouseleave(function() {
$(#container).html();
});
你忘记了jQuery选择器中的引号:
$("#ovr").mouseenter(function() {
$("#container").html("wazaap");
}).mouseleave(function() {
$("#container").html("");
});
编辑
如果你想要不同的句子,你可以这样做:
.JS
var description=new Array();
description["one"]="Here comes the first";
description["two"]="And here the second";
description["three"]="Now let's have the third";
description["four"]="Finally the last one, fourth";
$("a.link").mouseenter(function(){
$("span#description").text(description[$(this).attr("id")]);
}).mouseleave(function(){
$("span#description").text("");
})
.HTML
<a href="#" class="link" id="one">one</a>
<a href="#" class="link" id="two">two</a>
<a href="#" class="link" id="three">three</a>
<a href="#" class="link" id="four">four</a>
<span id="description"></span>
在此处检查工作http://jsfiddle.net/Wpe2B/
尝试使用hover()
函数来做到这一点。代码会更干净。
基本示例:
j查询:
$("#container").hover(
function() {
$('.cText').text("click");
},
function() {
$('.cText').text("");
});
.CSS:
#container {
position: relative;
background-color: #EEEEEE;
width: 100px;
height: 100px;
position: relative;
display: block;
}
.HTML:
div id="container"></div><span class="cText"></span>
问候
更新
基于OP的评论想要使用多个链接来显示文本,我尝试了这个:
http://jsfiddle.net/cZCRh/4/
它不适用于类,因为所有链接都获得相同的文本
这适用于 http://jsfiddle.net/cZCRh/1/
<div id="container"></div>
<a href="#" id="ovr">clickclickclick</a>
$("#ovr").mouseenter(function() {
$('#container").html("wazaap");
}).mouseleave(function() {
$("#container").html("");
});
问题是鼠标离开在错误的位置以及元素ID周围缺少引号
相关文章:
- 基于文本jquery php更改按钮
- 选择“p文本jquery”
- 附加 HTML 转义文本:jQuery
- 如何知道选中/突出显示的文本jquery的顺序出现
- Action.on('模糊')不't处理输入文本-jQuery 1.9+
- 在当前工具提示文本 JQuery 旁边追加或添加新文本
- 文本自动移动以适应动画相邻文本 (jquery):如何平滑
- 获取锚点的特定文本 - jQuery
- 从文本 jquery 中查找和挑选出模式
- 延迟后如何更改文本 - jQuery.
- 更改按钮文本 jQuery
- 使用 :包含 找到一个文本 jquery
- 获取引导程序单选按钮文本-jquery
- onchange函数转换为输入文本JQuery的数组
- 语法错误未终止字符串文本jquery
- 将输入占位符文本与span文本jquery交换
- 更改数值为文本- jQuery / NivoSlider
- 在文本区搜索指定的文本- jQuery/Javascript
- 一个字一个字地突出显示文本(jquery)(关闭)
- 无终止字符串文本jquery或更多