I`ve一個href值的末尾得到這個鏈接:附加到與jquery
<a id="Link" href="mailto:[email protected]?subject=I-Drain Bestellung&body="></a>
現在我想從表單元素附加數據後&體=」
因此,例如第一次更改爲&body="New text
,並在下一次更改爲 &body="New text , Another text
。
我怎樣才能做到這一點?不容得到它的工作..謝謝:)
I`ve一個href值的末尾得到這個鏈接:附加到與jquery
<a id="Link" href="mailto:[email protected]?subject=I-Drain Bestellung&body="></a>
現在我想從表單元素附加數據後&體=」
因此,例如第一次更改爲&body="New text
,並在下一次更改爲 &body="New text , Another text
。
我怎樣才能做到這一點?不容得到它的工作..謝謝:)
您更改鏈接的屬性:
var link = $('#Link');
link.attr('href', link.attr('href') + 'your text');
爲我工作。謝謝 –
@MarcSter如果有效的話也接受答案! –
不得不等待幾分鐘..當然我會接受它 –
例如,你可以做到這一點:
var form = $('.form_element').val();
var el = $('a#Link').prop('href');
el.prop('href', el.prop('href')+form);
$('#Link').attr('href',$('#Link').attr('href')+"New Text")
您可以使用純JS:
var el = document.getElementById('link');
el.href += 'some string';
當總是嘗試在jQuery上使用JS,通常它會提供更好的性能,因爲它減少了函數調用的次數。
謝謝:)也是個好主意 –
更多代碼請讓我們根據您的需要調整它 –
請發佈您嘗試過的代碼無法使用的代碼。 –
重複: http://stackoverflow.com/questions/2805742/how-to-update-append-to-an-href-in-jquery – Akrasiac