簡體   English   中英

如何在表單輸入中添加文本

[英]How to add text to form input

我真的不知道從哪里開始。 我有一個表單輸入框和提交按鈕。 當按下提交按鈕時,表單內容被提交並在一些 javascript 中使用。 我想要做的是在提交的末尾自動添加一些文本。

因此,如果用戶輸入“The dog walks”並按下提交,表單將添加“穿過街道”。 到提交結束。

謝謝!!

在表單提交操作的事件偵聽器中,更改輸入。

document.getElementById('theinputid').value = document.getElementById('theinputid').value + "across the street."

W3 學校是你的朋友: Form onsubmit 活動
所以在你的情況下,它類似於:

<script type="text/javascript">
    function addText() {
        var input = document.getElementById('something');
        input.value = input.value +' across the street';
    }
</script>

<form name="frm1" action="?" onsubmit="addText()">
    <input type="text" name="somehting" id="something" />
    <input type="submit" value="Submit" />
</form>

您可以使用+= ,例如:

input.value += 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM