如何在输入框中添加附加值

时间:2019-08-15 12:21:45

标签: javascript html

我正在尝试编辑自定义php / JS脚本输入框,以便发送带有用户输入值的自定义后缀。但是到目前为止,我还没有成功。

我需要在地址变量中添加“,UK”。

我已经尝试过

enum Markdown {
case text(String)
case sourceCode(code: String, language: Language)
indirect case tableCell(either "text" or "sourceCode")
indirect case tableRow(only table cells allowed)
indirect case table(only tableRow allowed)
}

但是没有运气。

var address = search_form['address'].value + ",UK",

我只是没有看到地址var附加“,UK”

2 个答案:

答案 0 :(得分:1)

也许这就是您需要的?

search_form['address'].value = search_form['address'].value + ", UK";

答案 1 :(得分:0)

您需要在附加之前存储旧值,然后可以在新变量中创建新值,例如:

var old_address = search_form['address'].value;
var new_address = old_address + ", UK";

您还可以通过使用附加赋值运算符+=来追加,例如:

var address = search_form['address'].value;
address += ", UK";

工作示例1:

var address = "Mike Address";
address += ", UK ";
console.log(address);	

工作示例2:

var address = "Mike Address";
var new_address = address+", UK ";
console.log(new_address);