简体   繁体   English

javascript加载时触发不单击

[英]javascript fires on load not click

My goal: Have an img in the defalt tab when the page loads. 我的目标:页面加载时,在defalt标签中有一个img。 The user clicks on the img and it fades to revile the tab below. 用户单击img,它消失,以重新显示下面的标签。

My problem: With in my html page I've placed a img tag. 我的问题:在html页面中,我放置了一个img标签。 In the header there's a javascript that successfully fades the img when it's clicked. 标头中有一个JavaScript,可在单击img时成功淡化img。 However when the img is placed with in the content section of "Tabs" area the fade fires when I load the page. 但是,当将img与“制表符”区域的内容部分放置在一起时,在加载页面时会淡入淡出。 I'm sure there's a conflict between the two scripts. 我确定这两个脚本之间存在冲突。 My fade script (on the html page) and the external javascript running the "Tabs". 我的淡入淡出脚本(在html页面上)和运行“标签”的外部javascript。

A side note: I've done countless arrangements placing the img tag with in the html tag layout. 旁注:我已经做了无数次安排,将img标签与html标签布局一起放置。 As well working with the css. 以及与CSS合作。

thanks for any advice. 感谢您的任何建议。

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8" />

<title>page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link rel="stylesheet" href="CSS/style13.css" type="text/css" media="screen" /> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 

<script src="Js/tabs.js" type="text/javascript"></script>

<link rel=stylesheet type="text/css" href="tabstyle.css" /><script>

$(document).click(function(){
   $("img").fadeOut('slow', function() {
       $("img").removeClass();
      });
});
</script>

</head>
<body>

<div class="WRAPPER">

<img src="images/tvOff.jpg" width="760" height="523">

<p class="dropcontent">

<div id="cyclelinks"></div>
</p>

<p class="dropcontent">
<img src="images/tvOn.jpg" width="760" height="523">
</p>

<p class="dropcontent">
<img src="images/logo1.png" >
</p>

</div><!--WRAPPER CLOSE-->`enter code here`
<div class="tvBase"></div>


</body>
</html>

You placed the click on the entire document, not just images. click了整个文档,而不仅仅是图像。 You also fade all images, not just the clicked one. 您还可以淡化所有图像,而不仅仅是淡入淡出。

$("img").click(function(){
   $(this).fadeOut('slow', function() {
       $(this).removeClass();
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM