我写了这个jquery代码:
$(document).ready(function(){
var info = $('.info').detach();
$('.des').click(function(){
score = score + 1;
played = played + 1;
$('.kreis').addClass("borderGreen");
$('.foto').hide();
$('.kreis').append(info);
});
$('.pro').click(function(){
played = played + 1;
$('.kreis').addClass("borderRed");
$('.foto').hide();
$('.kreis').append(info);
console.log('score:' + score);
console.log('played:' + played);
});
$('.frage').mouseenter(function(){
$(this).fadeTo(460, 0.7);
});
$('.frage').mouseleave(function(){
$(this).fadeTo(350, 0);
});
});
实现类似this!
的目标然后我编写了以下php代码来循环使用" function"
<?php foreach ($objects as $object){ ?>
<div class="kreis">
<div class="info" >
<div class="infobox">
<p style="padding-bottom:15px;border-bottom:1px solid #545454;"><?php echo $object["name"]; ?></p> <bl/>
<p style="font-weight:200;"><?php echo $object["position"]; ?></p>
</div>
<div class="social">
<a href="<?php echo $object["twitter"]; ?>"><img src="img/twitter.png" style="width:45px;margin-left:35px;padding-right:12px;"></a>
<a><img src="img/dribbble.png" style="width:45px;"></a>
</div>
</div>
<div class="foto" style="background-image:url('<?php echo $object["img"]; ?>'); ">
<div class="frage">
<div class="des box"><p>AAAAA</p></div>
<div class="pro box" style="margin-top:6%;"><p>BBBBB</p></div>
</div>
</div>
</div> <?php } ?>
现在的问题是,如果单击.des或.pro对象,jquery会隐藏每个对象的图层。有没有办法可以实现我想用jquery做什么,还是我必须使用javascript或其他语言?解决这个问题最优雅的方法是什么?
答案 0 :(得分:1)
jQuery非常适合这项工作。你可以坚持下去。 但是你必须改变只有点击监听器中的当前对象被改变而不是所有对象。试试这个:
$('.des').click(function(){
var $this = $(this);
score = score + 1;
played = played + 1;
$this.closest('.kreis').addClass("borderGreen").append(info);
$this.closest('.foto').hide();
});
$('.pro').click(function(){
var $this = $(this);
played = played + 1;
$this.closest('.kreis').addClass("borderRed").append(info);
$this.closest('.foto').hide();
console.log('score:' + score);
console.log('played:' + played);
});