[英]How can I get the value of an HTML variable and store it inside a javascript variable?
我這里有這行代碼。 這幾乎是HTML中的一個文本字段,它獲取鍵入的值並將其存儲在名為“ inpKeyword”的ID中。
<input type="text" name="keyword" value="Keyword" size="25" id="inpKeyword"/> <!-- enter search term -->
我需要將該值存儲在javascript var變量中。 有人可以幫幫我嗎? 在過去的幾個小時中,我一直在解決這個問題。 提前致謝!
順便說一句,這些都在JSP頁面中。
你有嘗試過嗎?
var val = document.getElementById('inpKeyword').value;
或者,您可以使用jQuery:
var value = $('#inpKeyword').val();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.