0

クリックに基づいてインラインスタイルを追加したい:

css:

div#ProductImages > img
{
    opacity:0.4;
    filter:alpha(opacity=40); /* For IE8 and earlier */
}

div#ProductImages > img:hover
{
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}

したがって、子画像アイコンの1つをクリックすると、不透明度は1.0になります。

これは私が試したことです:

$("div#ProductImages > img").click('style', 'opacity: 1.0', 'filter:alpha(opacity=100)');

どちらがうまくいかないようですか?

4

4 に答える 4

0
$("div#ProductImages > img").click( function() {
    $(this).css('opacity' , '1.0');
});
于 2012-05-30T11:09:28.370 に答える
0

あなたはこれを使ってみることができます:

$("div#ProductImages > img").click(function(){
    $(this).css({'opacity':'1.0'});
});
于 2012-05-30T11:15:47.670 に答える
0

他の人が示唆しているように、必要な属性を持つクラスを使用し、必要に応じてそれを追加/削除するのがおそらく最善です。hoverまた、あなたの質問では、CSSはを参照していますが、JavaScriptはを参照していることにも注意してくださいclick。このデモンストレーションではhover、jQueryのイベントハンドラーへの露出を向上させるために使用します。

Css

div#ProductImages > img
{
    opacity: 0.4;
    filter: alpha(opacity=40);
}

div#ProductImages > img:hover,
div#ProductImages > img.onHover
{
    opacity: 1.0;
    filter: alpha(opacity=100);
}

JavaScript(jQueryを使用)

$('div#ProductImages > img').hover(function()
{
    $(this).addClass('onHover');
}, function()
{
    $(this).removeClass('onHover');
});
于 2012-05-30T11:16:14.573 に答える
0

これを試して:

$("div#ProductImages > img").click(function(){
    $(this).addClass('newClassName'); 
});

cssは次のとおりです。

.newClassName{
   opacity:1.0;
   filter:alpha(opacity=100); 
}
于 2012-05-30T11:08:52.253 に答える