在 gridview 项目模板中,当 div 设置为不显示时,如何在鼠标悬停时显示/隐藏 div

发布于 2025-01-07 17:19:17 字数 388 浏览 3 评论 0原文

box div 将在页面加载期间隐藏,当我们将鼠标悬停在其上时,它应该显示,onmouseover 时它应该显示,onmouseout 时它应该隐藏。任何人都可以建议我如何在 jquery 中执行此操作,我是 Jquery 的初学者:)

更新此 Div 放置在 gridview 的 ItemTemplate 中。会起作用吗?你们提供了哪些答案?

<div id="box" style="display: none">
   <a href="#" class="bt btleft">Highlight it</a>
   <a href="#" class="bt btright">Reset</a>
</div>

box div will be hidden during pageload, when we hover on it it should display, onmouseover it should display, and onmouseout it should be hidden. can any body suggest me how to do in jquery, i am beginner in Jquery :)

Update this Div is placed in ItemTemplate of gridview. will it be worked ? with answeered which you people provide ?

<div id="box" style="display: none">
   <a href="#" class="bt btleft">Highlight it</a>
   <a href="#" class="bt btright">Reset</a>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

寄意 2025-01-14 17:19:17

你最好在CSS中使用visible属性,而不是从display:none开始,因为display:none会删除容器本身的空间。

试试这个

http://jsfiddle.net/sfUHn/7/

您的 HTML 应该如下

<div id='container'>
 <div id="box" style="visibility: hidden">
 <a href="#" class="bt btleft">Highlight it</a>
 <a href="#" class="bt btright">Reset</a>
 </div>
</div>​

所示jquery 看起来像这样

 $("#container").hover(function () {
$("#container div").css("visibility","visible");
  },
  function () {
    $("#container div").css("visibility","hidden");
  });​

希望这有帮助

you are better off using visible property in CSS rather than display:none to start with because display:none will sort of remove the space of the container itself.

try this out

http://jsfiddle.net/sfUHn/7/

Your HTML should look like this

<div id='container'>
 <div id="box" style="visibility: hidden">
 <a href="#" class="bt btleft">Highlight it</a>
 <a href="#" class="bt btright">Reset</a>
 </div>
</div>​

You jquery will look like this

 $("#container").hover(function () {
$("#container div").css("visibility","visible");
  },
  function () {
    $("#container div").css("visibility","hidden");
  });​

Hope this helps

口干舌燥 2025-01-14 17:19:17

修改html有点像

<div id="hover">hover</div>
<div id="box" style="display: none">
   <a href="#" class="bt btleft">Highlight it</a>
   <a href="#" class="bt btright">Reset</a>
</div>

jquery部分

$("#hover").hover(function(){
  $("#box").slideDown();

},function(){
     $("#box").slideUp(); 
});

DEMO

modify the html a bit like

<div id="hover">hover</div>
<div id="box" style="display: none">
   <a href="#" class="bt btleft">Highlight it</a>
   <a href="#" class="bt btright">Reset</a>
</div>

jquery part

$("#hover").hover(function(){
  $("#box").slideDown();

},function(){
     $("#box").slideUp(); 
});

DEMO

匿名的好友 2025-01-14 17:19:17

将其包装在另一个 div 中并在该 div 上绑定鼠标悬停事件

<div id='parent-wrapper'>
  <div id="box" style="display: none">
     <a href="#" class="bt btleft">Highlight it</a>
     <a href="#" class="bt btright">Reset</a>
  </div>
</div>

$('#parent-wrapper')
 .mouseover( 
   function() {
    $('#box').show();
   } 
 );

wrap it in another div and bind a mouseover event on that div

<div id='parent-wrapper'>
  <div id="box" style="display: none">
     <a href="#" class="bt btleft">Highlight it</a>
     <a href="#" class="bt btright">Reset</a>
  </div>
</div>

$('#parent-wrapper')
 .mouseover( 
   function() {
    $('#box').show();
   } 
 );
椵侞 2025-01-14 17:19:17

试试这个,最简单的..

$("#box").hover(function()
{
  $(this).show();
},
function()
{
  $(this).hide();
});

Try this, the simplest one..

$("#box").hover(function()
{
  $(this).show();
},
function()
{
  $(this).hide();
});
蓝天 2025-01-14 17:19:17

用另一个 div 包裹 div 并将代码添加到包裹的 div 中:

$('#wrapper').bind('mouseover hover', function(){

     $('#box').show();

});


$('#wrapper').mouseout(funcion(){

    $('#box').hide();

});

Wrap the div with another div and add the code to that wrapped div:

$('#wrapper').bind('mouseover hover', function(){

     $('#box').show();

});


$('#wrapper').mouseout(funcion(){

    $('#box').hide();

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文