我有几个复选框。当我将鼠标悬停在它们上面时,我想显示一些与这些复选框相关的信息。我该如何使用JS或JQuery实现?假设这是我的复选框:
<input type="checkbox" value="monday" checked="checked">
我想向用户展示“ Hello User”或值为“ monday”的数据,或来自我的数据库的一些数据。如何实现?
我有几个复选框。当我将鼠标悬停在它们上面时,我想显示一些与这些复选框相关的信息。我该如何使用JS或JQuery实现?假设这是我的复选框:
<input type="checkbox" value="monday" checked="checked">
我想向用户展示“ Hello User”或值为“ monday”的数据,或来自我的数据库的一些数据。如何实现?
只需在您的HTML对象中添加一个"title"属性。
<input title="Text to show" id="chk1" type="checkbox" value="monday" checked="checked" />
或者使用 JavaScript
document.getElementById("chk1").setAttribute("title", "text to show");
或者使用jQuery
$('#chk1').attr('title', 'text to show');
input type='checkbox' title='tooltip 2'
您可以使用JS插件(需要将所需文本的值作为属性添加,请参阅文档)http://onehackoranother.com/projects/jquery/tipsy/
这里是您的答案:
<input type="checkbox" value="monday" checked="checked">
<div>informations</div>
和 CSS:
input+div{display:none;}
input:hover+div{display:inline;}
你可以在这里找到一个示例。
有这样的HTML结构:
<div class="checkboxContainer">
<input type="checkbox" class="checkboxes"> Checkbox 1
<div class="infoCheckbox">
<p>Info on checkbox 1</p>
</div>
</div>
<div class="checkboxContainer">
<input type="checkbox" class="checkboxes"> Checkbox 2
<div class="infoCheckbox">
<p>Info on checkbox 2</p>
</div>
</div>
<div class="checkboxContainer">
<input type="checkbox" class="checkboxes"> Checkbox 3
<div class="infoCheckbox">
<p>Info on checkbox 3</p>
</div>
</div>
$(".checkboxContainer").hover(
function() {
$(this).find(".infoCheckbox:first").show();
},
function() {
$(this).find(".infoCheckbox:first").hide();
}
);
<input type="checkbox" id="cb" value="monday" checked="checked">
$("#cb").hover(
function() {
// show info
},
function() {
// hide info
}
);
或者你可以在元素中添加title属性
快速粗略地尝试一下(未经测试或任何东西,并且并不完全理解您想要什么...更不用说您实际尝试了什么...也许可以尝试以下内容...
$('input:checkbox').mouseover(function()
{
/*code to display whatever where ever*/
//example
alert($(this).val());
}).mouseout(function()
{
/*code to hide or remove displayed whatever where ever*/
});
当然有很多方法可以做同样的事情,从使用 toggle()
到使用 on()
等等。