0

宣伝文句のリンクをクリックすると、プレビュー ウィンドウに完全な説明が表示される機能に取り組んでいます...Google などの検索エンジンの検索結果のプレビューによく似ています。

完全な説明テキストとイベントの両方を処理関数に渡して、何を表示し、どこに表示するか (宣伝文句の下) を関数が認識できるようにする必要があります。

私の質問は、関数に何を渡すべきかということです。現在、私は以下を持っていますが、機能していません。

<a href="javascript:DisplayFullDescription('blah blah description goes here');">blurb text here</a>

function javascript:DisplayFullDescription(e, fullText){
   //find out mouse click position
   //display a preview window (div) with description there

 }
4

3 に答える 3

2

HTML5 を使用していない場合、個人的には、全文の隠し要素を で作成し、display:none該当する各要素にデータとして割り当て、その情報を使用します。click

<a class="clickable" href="#">blurb text here<span style="display:none">blah blah description goes here</span></a>

$('a.clickable').each(function() {
    $(this).data('fulltext',$(this).find('span').remove().text());
}).click(function(event) {
    event.preventDefault();
    $('body').append('<div>'+$(this).data('fulltext')+'</div>');
})
于 2012-08-22T16:03:17.877 に答える
1

属性を使用するよりも、jQuery を使用してイベント ハンドラーをバインドし、HTML5data-*属性を使用して全文を格納する方がはるかに簡単onclickです。

HTML:

<a href="#" data-fulltext="blah blah description goes here">blurb text here</a>

jQuery/JavaScript:

$('a').click(function(e) {
    DisplayFullDescription(e, $(this).data('fulltext'));
    e.preventDefault();
});

function DisplayFullDescription(e, fullText){
    //find out mouse click position
    //display a preview window (div) with description there
}
于 2012-08-22T15:49:20.877 に答える