Javascript 选择面时更改块引号
我已经编写了很多代码()并且我几乎完成了,但是当你点击一个人的脸时,我需要一些切换的东西,然后引号(如果你看不到它,在结果处向下滚动)将更改为该人的引号 我在JS中已经有了一个开关,这个部件:Javascript 选择面时更改块引号,javascript,Javascript,我已经编写了很多代码()并且我几乎完成了,但是当你点击一个人的脸时,我需要一些切换的东西,然后引号(如果你看不到它,在结果处向下滚动)将更改为该人的引号 我在JS中已经有了一个开关,这个部件: $(function() { var $profiles = $("#profile1, #profile2, #profile3, #profile4, #profile5, #profile6, #profile7, #profile8, #profile9, #profile10, #pro
$(function() {
var $profiles = $("#profile1, #profile2, #profile3, #profile4, #profile5, #profile6, #profile7, #profile8, #profile9, #profile10, #profile11");
$profiles.click(function(e) {
$profiles.removeClass("focused");
$(this).addClass("focused");
});
});
但我需要把它和引语结合起来
如果你真的不想帮我解决具体的问题,我很乐意用伪代码或者帮助我思考。我已经坐在这一块太久了,现在能够直接思考
你推荐什么
大家干杯,你们太棒了 您的blockquote中必须有某种引用,例如一个数据属性,它指示quote属于哪个概要文件。例如:
<blockquote data-profileid="profile8">
<p>
"Sist är starkast... eller något sånt."
</p>
</blockquote>
我这样解决了你的问题:
var id = $(this).attr('id');
$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提琴,并测试了它的工作原理。伙计,那简直是杀手锏!非常感谢!