0

私の論理は理にかなっているように感じます。残念ながら、そうではありません:(?
更新:livecode 質問: mouseenterでそのテキストを取得してのテキストに設定する
にはどうすればよいですか?$(this).attr.('title')('HGROUP h1')

jQuery

$("div.box").on('mouseenter', function () { //select the box create mouseenter function
    var headerText = $(this).attr('title'); //get selected title and set to headerText
    $('HGROUP h1').text(headerText); //set hgroupd h1 text to headerText
});

$("div.box").on('mouseleave', function () { //select the box create mouseleave function
    $('HGROUP h1').text('DESIGNOBVIO.US'); //set the orginal text back in place on mouseleave
});

HTML

<div class="box">
<h1 title="can i haz it?2"></h1>
<div class="innerbox">
    <figure></figure>
    <ul class="categorySelect">
        <li class="misc"></li>
        <li class="print"></li>
        <li class="video"></li>
        <li class="web"></li>
    </ul>
</div>

Hgroup HTML

<HGROUP>
 <h1>designobvio.us</h1>
 <h2>the colors duke, the colors!7</h2>
</HGROUP>

私がどこで失敗したかについてのさらなる説明は素晴らしいでしょう。

4

3 に答える 3

1

使用する必要があるようです:

var headerText = $(this).find('h1:first').attr('title');
于 2012-06-06T19:18:49.610 に答える
1

これを変える:

var headerText = $(this).attr('title');

に:

var headerText = $(this).find('h1').attr('title');

あなたのコードは、子ではなくdivのタイトルを取得しようとしています<h1>

于 2012-06-06T19:19:07.613 に答える
0

タイトルを取得するには、findを使用する必要があります。

var headerText = $(this).find('h1').attr('title');

これを試して :

  $("div.box").on('mouseenter', function () { 
 //select the box create mouseenter function
  var headerText = $(this).find('h1').attr('title'); 
  //get selected title and set to headerText
   console.log(headerText);
    $('HGROUP h1').text(headerText); //set hgroupd h1 text to headerText
 });

 $("div.box").on('mouseleave', function () { 
       //select the box create mouseleave function
     $('HGROUP h1').text('DESIGNOBVIO.US'); 
     //set the orginal text back in place on mouseleave
 });​

これがデモです

于 2012-06-06T19:22:55.093 に答える