2

簡単な JQuery ソリューションを使用して、リンクから href を取得し、クリック イベントに適用しています。これは Webkit および Gecko ブラウザーで機能しますが、Internet Explorer (7 & 8) では href の場所がundefinedとして表示され続けます。誰でもこれを修正できますか?これを解決するのを手伝ってもらえますか? もしそうなら大歓迎です。

 $('table tr').click(
    function () {
        var element = $(this).attr("class");
        var hrefLocation = $('#'+ element +' .deal-holder a').attr('href');
        alert(hrefLocation)
        window.location.href = hrefLocation;
        return false; 
    }
);

HTML は単純です。

 <tr class="QRG">
    <td class="blue"><a href="#QRG">QRG</a></td>
    <td>Company Sale</td>
    <td>Technology</td>
 </tr>


 <div class="deal" id="QRG">
      <p><span class="js">Overview</span><span class="no-js">Enham</span></p>
      <div class="deal-holder">
         <div class="image-holder">
             <img src="../assets/images/enham.gif" alt="" height="70" width="150" />
         </div>
         <p>Enham is a charity established in 1918, which delivers a wide range of essential services that provide choice and empowerment to disabled people to make their own decisions about their lives. Enham is a charity established in 1918, which delivers a wide range of essential services that provide choice and empowerment to disabled people to make their own decisions about their lives</p>
         <a class="moreInfo" href="individual.html">More Information</a>
      </div>
 </div>
4

4 に答える 4

4

間違っていても、私に飛びつくものは何もありません。

まず、最新バージョンの jQuery を使用していることを確認してください。

コードを変更して、 内のリンクにtrクリック イベントが含まれるようにします。

$('table tr a').click(function (e) {
    var element = $(this).closest('tr').attr("class"),
        hrefLocation = $('#'+ element +' .deal-holder a').attr('href');
    alert(hrefLocation)
    window.location.href = hrefLocation;
    e.preventDefault();
});

ここでデモを行い、IE 7、8、および 9 で動作します。これが役立つことを願っています。

于 2011-08-15T15:31:30.030 に答える
1

HTMLコードの残りの部分を知らなければ、何が問題なのかを正確に知ることは難しく、動作はHTMLの構造に大きく依存します...しかし、ここで簡単なテストを行うとうまくいきます:$(this) .

于 2011-08-15T15:40:59.813 に答える
0

ハイパーリンクのグループの最初の要素を選択する必要がある場合があります。

$('table tr').click(
    function () {
        var element = $(this).attr("class");
        var hrefLocation = $('#'+ element +' .deal-holder a').eq(0).attr('href');
        alert(hrefLocation)
        window.location.href = hrefLocation;
        return false; 
    }
);
于 2011-08-15T15:44:43.123 に答える
0

ready 関数でラップしてみてください。
IE は、オブジェクトが DOM に入る前に、イベントをオブジェクトに追加しようとしている可能性があります。

$(document).ready(function(){

   $('table tr').click(
      function () {
         var element = $(this).attr("class");
         var hrefLocation = $('#'+ element +' .deal-holder a').attr('href');
         alert(hrefLocation);

         window.location.href = hrefLocation;
         return false; 
      });

});
于 2011-08-16T17:21:10.140 に答える