2013-12-16 38 views
0

我有以下鏈接編輯鏈接的name屬性

<section class="col-sm-12 les_navigation"> 
    <a id="home" href="">Home</a> 
    <a id="about" href="">About</a> 
    <a id="resume" href="">Resume</a> 
     <a id="portfolio" href="">Portfolio</a> 
     <a id="blog" href="">Blog</a> 
     <a id="contact_me" href=""></a> 
    </section> 

和最後一個環節有一個空白的name屬性

<a id="contact_me" href=""></a> 

我想附加每個窗口的當前寬度與此代碼調整

$(window).resize(function() { 
var current_width = $('.les_body').width(); 
$('#contact_me').attr('name',current_width); 
}); 

但是,新的寬度不會追加。如何解決這個問題?

+2

要電流寬度追加到href屬性或想添加一個名爲「名稱」的另一個屬性? – gulshanm01

+0

我想用''#contact_me'將當前寬度附加到href。 –

+2

將'name'更改爲'href'。 '名字'什麼都不是。 – stefancarlton

回答

0

使用本

$(window).resize(function() { 
var current_width = $('.les_body').width(); 
$('#contact_me').attr('href',current_width); 
}); 
0

試試這個隊友,如果u需要有HREF replaced.You沒有命名name的屬性,在<a id="contact_me" href=""></a>

$(window).resize(function() { 
    var current_width = $('.les_body').width(); 
    $('#contact_me').attr('href',current_width); 

//如果u需要文本替換嘗試

// $('#contact_me').text(current_width); 

//如果您想要append th在價值的href標記try.So如果您current href is contact和寬度是400那麼你的新hrefcontact400

// $('#contact_me')..attr('href', $(this).attr('href') + current_width); 
});