0
<script type="text/javascript">
$(function() {

    $('.thelink a').select(function() {

        var a_href = $(this).attr("href");

    });
    $('.calltoActionMoreInformation a').attr('href', a_href);
});
</script>

  <div class="thelink" style="height: 250px; position: relative;">
  <a title="xxx" href="xxx">
    <img alt="tree" src="x" />

  </a>
  </div>

内部からhrefを入れようとしています:

  <span class="calltoActionMoreInformation" style="position: absolute; bottom: 0px;">
   <a title="" href="--Link here--"></a>
  </span>

var a_href = 'http://www.google.co.uk'; を設定した場合 正しく設定されるため、問題は .thelink div. 内のリンクのみの href を取得することにあります。

.thelink a の href を .calltoActionMoreInformation a に割り当てるにはどうすればよいですか?

4

3 に答える 3

7
$('.thelink a').click(function(e) {
   e.preventDefault();
   var a_href = $(this).attr("href"); // or this.href
   $('.calltoActionMoreInformation a').attr('href', a_href);
});

デモ

于 2012-06-13T15:30:17.620 に答える
0
$('.thelink a').click(function() {
   var a_href = $(this).attr("href");
   $('.calltoActionMoreInformation a').attr('href', a_href);
   return;
});
于 2012-06-14T17:07:20.030 に答える
0

1 - 変数 "a href" は、グローバル コンテキストからはアクセスできませんが、select 関数からのみアクセスできます。

2 - この場合、「選択」機能「クリック」を使用する方が適切な理由

修正 :

$(function(){

    $('.thelink a').click(function(e) {
        $('.calltoActionMoreInformation > a').attr('href', $(this).attr('href'));
            e.preventDefault(); // or
        return false; // this is important is you dont want the browserfollow the link
    });

});

それは正しいですか?

于 2012-06-13T15:44:51.953 に答える