我有一個輸入和一個鏈接。當用戶鍵入內容時,我需要更改鏈接的href值,如果還有一種方法可以檢測用戶是否在其中粘貼了某些內容,那麼這將會非常棒。用文本輸入值隨時更改鏈接href屬性
任何想法如何通過jQuery實現這一點?
<input type="text" id="my-input">
<a id="my-link" target="_blank" href="www.something.com/<!--input text here-->/something/">
Click me!
</a>
我已經挖了起來:
//Somehow get the the input value if it has changed
//Change the href attribute
$("#my-link").attr("href", "//www.something.com/" + textFromInput +"/something/");
把你的代碼放在輸入的'change'事件中。 – Barmar
您可以複製粘貼我的代碼並將您的建議添加爲答案,以便我可以看到它的樣子嗎?謝謝。 – Solo
綁定事件處理程序是最基本的jQuery操作之一。請展示你的嘗試,然後我可以幫助你瞭解你做錯了什麼。 – Barmar