[英]Pass variable in function js
我有代碼:
<td><input type="hidden" id="someText" name="someText" value="Hello World!"> </td>
<td><button onclick="test(document.getElementById('someText'))">Invoke Some</button></td>
我想將someText傳遞給我的test()。 但是我得到了[object HTMLInputElement]。 我必須在html中傳入它
您正在傳遞元素對象,您需要訪問其value
<td><button onclick="test(document.getElementById('someText').value)">Invoke Some</button></td>
已更換
test(document.getElementById('someText'))
與
test(document.getElementById('someText').value)
使用div的id來獲取其中的值並將其傳遞給函數。
<input type="hidden" id="someText" name="someText" value="Hello World!"> </td>
<td>
<button onclick="test(document.getElementById('id of your div').value)">Invoke Some</button>
</td>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.