我已经写了很多代码(JS fiddle project)而且我差不多完成了,但是当你点击一个人的脸,然后是引号时,我需要一些切换的东西我是JS(如果结果向下滚动你不能看到它会改变那个人的引用。
我已经在JS中使用了这一部分进行了切换:
$(function() {
var $profiles = $("#profile1, #profile2, #profile3, #profile4, #profile5, #profile6, #profile7, #profile8, #profile9, #profile10, #profile11");
$profiles.click(function(e) {
$profiles.removeClass("focused");
$(this).addClass("focused");
});
});
但我需要以某种方式将它与引号结合起来。
如果你真的不想帮我解决具体问题,我只会对伪代码或如何思考的帮助感到满意。为了能够直接思考,我已经和这件作品坐了很长时间。
你会推荐什么?
干杯,你们摇滚!
答案 0 :(得分:1)
你必须在你的blockquote中有一些引用,例如一个数据属性,它指示引用属于哪个配置文件。例如:
<blockquote data-profileid="profile8">
<p>
"Sist är starkast... eller något sånt."
</p>
</blockquote>
然后在onclick函数中,显示带有与所点击的id匹配的data属性的blockquote。您可以像这样获得点击的ID:
var id = $(this).attr('id');
答案 1 :(得分:1)
我解决了你的问题:
$profiles.click(function(e) {
var profileNr = parseInt($(this).attr("id").substring(7));
$profiles.removeClass("focused");
$(this).addClass("focused");
$(".thequote .show").removeClass("show");
$(".thequote blockquote").eq(profileNr-1).find("p").addClass("show");
});
它从配置文件编号中提取引用索引,然后使用jQuery eq()选择适当的引用。我也更新了你的JS Fiddle并测试它是否有效。