1

たとえば、次のコードをご覧ください。

$('.photo').hover(
            function() {
                //display heading and caption
                $(this).children('div:first').stop(true,false).animate({top:0},{duration:200, easing: 'easeOutQuart'});
                $(this).children('div:last').stop(true,false).animate({bottom:0},{duration:200, easing: 'easeOutQuart'})
})

この行で選択された要素を知りたいとしましょう:

$(this).children('div:first') 

対象の要素に警告することは何とか可能ですか? 私は試した:

something = $(this).children('div:first').val();
                alert (something);

また

something = $(this).children('div:first');
                alert (something);

最初の例では、空白のアラートが表示されます。2 つ目 - Objext オブジェクト。

よろしく、

4

2 に答える 2

1

もちろん!jQueryの選択でうまく機能するconsole.logを使用できます。

console.log($(this).children('div:first'));

FirefoxまたはChromeを使用している場合は、F12キーを押して開発者のコ​​ンソールを開き、[コンソール]タブに移動すると、選択内容と構造全体が表示されます。

これは、実際には、配列やオブジェクトなどを表示する場合にも非常に便利です。

于 2012-07-18T10:41:24.960 に答える
1

以下を使用できます。

something = $(this).children('div:first').text();
                alert (something);

また

something = $(this).children('div:first').html();
                alert (something);
于 2012-07-18T10:40:00.050 に答える