gpt4 book ai didi

javascript - 使用类名显示#ID+this.substring(1)(点)

转载 作者:行者123 更新时间:2023-11-28 20:31:35 25 4
gpt4 key购买 nike

我有几个具有相同类规范的 ID,但文本内容发生了变化。使用 jQuery,我想在单击函数上调用我的类 .job 以显示相应的 #paper_propertyjob

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

$(".job").click(function(){
var theclass:String = this;
var thejob:String = theclass.substring(1);
$("#paper_"+thejob).fadeIn(400);
});
</script>

我第一天就尝试了下一个,但没有结果:

<script type="text/javascript">
$(".job").click(function(){
$("#paper_"+ this).fadeIn(400);
});
</script>

HTML:

<div id="inge_sys" class="job" style= "background-image: url('src/img/salles/explo/ingesys.png')"></div>
<div id="cosmo" class="job" style= "background-image: url('src/img/salles/explo/cosmo.png')"></div>
<div id="astro" class="job" style= "background-image: url('src/img/salles/explo/astro.png')"></div>


<div id="paper_cosmo" class="paper">Text</div>
<div id="paper_astro" class="paper">Text</div>

最佳答案

我建议:

$(".job").click(function(){
$("#paper_"+ this.id).fadeIn(400);
});

如果您只想一次显示其中一个 .paper 元素:

$(".job").click(function(){
$('.paper').fadeOut(function(){
$("#paper_"+ this.id).fadeIn(400);
});
});

关于javascript - 使用类名显示#ID+this.substring(1)(点),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16252250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com