开发者

Would like to use .fadeTo elegantly

Here's what I've got far, which works:

var X = $('#myID input:checked').length;
if (X) {
    $('input[name=Save]').show();
} else {
    $('input[name=Save]').hide();
}

What I'd like to do is writ开发者_JAVA技巧e this elegantly using the .fadeTo method.

$('input[name=Save]').fadeTo(Y)

Where Y=1 if X > 0 AND Y=0 if X = 0.


Is this what you're after? It's not very elegant to read, but it's small (I haven't tested it, so tell me if it doesn't work):

$('input[name=Save]').fadeTo('fast', (X > 0) ? '1' : '0')

That random jargon stuff in the middle is basically what you originally wrote, but in a compact syntax. Here's a Wikipedia article about it, if you want to read it: http://en.wikipedia.org/wiki/%3F:#JavaScript


Unless you want partial opacity, just use fadeIn('slow')/fadeOut('slow') instead of hide/show

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜