【问题标题】:how to change opening a new window method如何更改打开新窗口的方法
【发布时间】:2014-05-25 19:55:43
【问题描述】:

我在网页中有下面的代码,它的工作是:当鼠标刚刚移到图像上时,会出现一个新窗口,当鼠标离开时,它就会消失。它所做的一切都很好,但我只想在我点击图像时显示它,当我在新窗口之外点击它时它消失。检查一下。需要帮助

标题中的代码:

<style type="text/css">
a.imPop {
position:relative;
z-index:0;
}  
a.imPop:hover {
display:inline;
z-index:auto;
} 
a.imPop span {  
display:none;  
}
a.imPop:hover span {
display:inline;
position:left;
top:1em;
left:1em;
width:128px;
height:128px;
}

</style>

正文中的代码:

<a class="imPop" title="" style="color:#0000FF" font:large""> 
 <img src="images/1.gif" alt="" /><span>

<img src="images/2.jpg alt="" />


        </span> </a>

【问题讨论】:

  • 给我们提个醒:jsfiddle.net 你将不得不使用某种类型的 javascript 来获取点击,因为我知道你无法使用 Css 获得点击事件
  • 您可以使用 :active,但这仅在按住鼠标时有效。我会推荐一些js。

标签: html css window


【解决方案1】:

如果你在页面上有类似这样的东西,它会在 jquery 中完成:

jQuery(document).ready(function($) {
    //this tracks the click on the class
    $('.imPop').on('click', function(event) {
        event.preventDefault();
        /* Act on the event */
              //this shows your span
        $('.imPop span').show();
    });
       //now this is flaky because you are looking for a click on the body tag of the   html it would be better to look for your page wrapper div and track clicks on that outside of the box
    $('body').on('click', function(event) {
        event.preventDefault();
        /* Act on the event */
           //this hide's the one you just showed!
        $('.imPop span').hide();
    });
});

把它放在结束标签之前:

<script>
jQuery(document).ready(function($) {
    $('.imPop').click( function(event) {
        event.preventDefault();
        /* Act on the event */
        $('.imPop span').show();
    });
    $('body').click(function(event) {
        event.preventDefault();
        /* Act on the event */
        $('.imPop span').hide();
    });
});
</script>

试试这个:

        <script>
jQuery(document).ready(function($) {
  $('.imPop').click( function(event) {
        event.preventDefault();
        /* Act on the event */
        $(this).children('span').show().addClass('showed');
    });
  $('body').click(function(){
    event.preventDefault();
    $('.showed').hide().removeClass('showed');
  });
});
    </script>

【讨论】:

  • 对jquery一无所知。如果这是我需要将此代码提供给专家以将其输入页面的唯一方法
  • 把页面的url发给我们,这里会有人告诉你放在哪里
  • 尝试下面的方法并从 css 中删除 a.imPop:hover {} 以确保它是 clikc 做的`
  • 我完全删除了那个 css 并且它起作用了。但是当我点击正文时并没有隐藏。我在(跨度)显示后添加了下面的代码但仍然没有:$('body').click(function(event){event.preventDefault(); / *行动事件 */ $(this).children('span').hide();
  • 还是什么都没有!!新代码的工作原理相同。它会出现,但不会隐藏。真的为什么不躲?!
猜你喜欢
  • 2020-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多