0

クラスの仕様は同じですが、テキストの内容が異なる ID がいくつかあります。.jobjQuery を使用して、クリック関数でクラスを呼び出して、適切な を表示したいと思います#paper_appropriatejob

<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>

次の最初のqthを試しましたが、結果もありませんでした:

<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>
4

2 に答える 2

1

まず第一に、これは有効な構文ではありません:

var theclass:String = this;

IDまたはクラスの文字列値が必要な場合は、これを使用してください:

var thisClass = $(this).attr('class');
// or 
var id = $(this).attr('id');

その後、あなたが望むことを行うことができます:

$("#paper_"+ thisClass).fadeIn(400);
于 2013-04-27T12:59:34.243 に答える