【发布时间】:2015-04-08 23:55:43
【问题描述】:
我是 javascript/jquery 新手,目前在使用 javascript/jquery 按钮单击时在灯箱中显示不同内容时遇到问题
我创建了两个按钮,它们应该在单击按钮时显示具有不同内容的灯箱。每个按钮的灯箱内的内容应该是不同的,目前情况并非如此。
当我尝试更改第一个按钮的第一个 h3 和 p 标记时,它与第二个按钮的第二个 h3 和 p 标记重叠。我认为问题出在 javascript 代码上,但我不知道如何在单击按钮时为每个灯箱显示不同的内容。
这是我的 HTML/Javascript 代码:
<!DOCTYPE html>
<html lang="no">
<head>
<title>FantasyLab</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
$(document).ready(function(){
$('.lightbox').click(function(){
$('.backdrop, .box').animate({'opacity':'.50'}, 300, 'linear');
$('.box').animate({'opacity':'1.00'}, 300, 'linear');
$('.backdrop, .box').css('display', 'block');
});
$('.close').click(function(){
close_box();
});
$('.backdrop').click(function(){
close_box();
});
});
function close_box()
{
$('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
$('.backdrop, .box').css('display', 'none');
});
}
</script>
</script>
</head>
<body bgcolor="#060e19">
<div class="page-wrap">
<a href="#" class="lightbox" id="contact">Kom i kontakt</a>
<div class="box">
<div class="close"><i class="fa fa-times fa-1x"></i></div> <!-- end of close -->
<h3 class="title">Kom i kontakt</h3>
<p>Kontakt oss for mer informasjon</p>
<div class="container">
<form id="newsletter-subscription" action="" method="post">
<fieldset>
<input placeholder="Fornavn" type="text" tabindex="1" required autofocus>
</fieldset> <!-- end of fieldset -->
<fieldset>
<input placeholder="Etternavn" type="text" tabindex="2" required autofocus>
</fieldset> <!-- end of fieldset -->
<fieldset>
<input placeholder="E-postadresse" type="email" tabindex="3" required>
</fieldset> <!-- end of fieldset -->
<fieldset>
<input placeholder="Telefonnummer" type="tel" tabindex="4" required>
</fieldset> <!-- end of fieldset -->
<fieldset>
<input placeholder="Webside http://" type="url" tabindex="5" required>
</fieldset> <!-- end of fieldset -->
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Send inn</button>
</fieldset>
</form> <!-- end of form -->
</div> <!-- end of container -->
</div> <!-- end of box-content -->
<a href="#" class="lightbox" id="subscribe">Meld deg på vår nyhetsbrev</a>
<div class="backdrop"></div> <!-- end of backdrop -->
<div class="box">
<div class="close"><i class="fa fa-times fa-1x"></i></div> <!-- end of close -->
<h3 class="title">Abonner på nyhetsbrev</h3>
<p>Motta informasjon rundt lanseringsdato, kampanjer og tilbud.</p>
<div class="container">
<form id="newsletter-subscription" action="" method="post">
<fieldset>
<input placeholder="Fornavn" type="text" tabindex="1" required autofocus>
</fieldset> <!-- end of fieldset -->
<fieldset>
<input placeholder="Etternavn" type="text" tabindex="2" required autofocus>
</fieldset> <!-- end of fieldset -->
<fieldset>
<input placeholder="E-postadresse" type="email" tabindex="3" required>
</fieldset> <!-- end of fieldset -->
<fieldset>
<input placeholder="Telefonnummer" type="tel" tabindex="4" required>
</fieldset> <!-- end of fieldset -->
<fieldset>
<input placeholder="Webside http://" type="url" tabindex="5" required>
</fieldset> <!-- end of fieldset -->
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Send inn</button>
</fieldset>
</form> <!-- end of form -->
</div> <!-- end of container -->
</div> <!-- end of box-content -->
</div> <!-- end of main-content -->
</div> <!-- end of page-wrap -->
</body>
</html>
感谢任何帮助。
【问题讨论】:
标签: javascript jquery html button lightbox