[英]How to add an additional value to a input box
I'm trying to edit a custom php/JS script input box so a custom suffix is sent with a user inputted value. 我正在尝试编辑自定义php / JS脚本输入框,以便使用用户输入的值发送自定义后缀。 But so far I haven't managed to succeed.
但是到目前为止,我还没有成功。
I need to add ",UK" onto the address variable. 我需要在地址变量上添加“,UK”。
I have tried this 我已经试过了
var address = search_form['address'].value + ",UK",
But no luck. 但是没有运气。
getCurrentLocations: function()
{
var self = this,
search_form = document.forms[self.opts.search_form_name],
address = search_form['address'].value,
radius = search_form['radius'].value;
I'm just not seeing the address var attaching ",UK" 我只是没有看到地址var附加“,UK”
也许这就是您所需要的?
search_form['address'].value = search_form['address'].value + ", UK";
You need to store old value before appending, then you can create new value in new variable like: 您需要在存储附加值之前存储旧值,然后可以在新变量中创建新值,例如:
var old_address = search_form['address'].value;
var new_address = old_address + ", UK";
You can also append by using addition assignment operator +=
like: 您还可以通过使用附加赋值运算符
+=
进行附加,例如:
var address = search_form['address'].value;
address += ", UK";
Working Example 1: 工作示例1:
var address = "Mike Address"; address += ", UK "; console.log(address);
Working Example 2: 工作示例2:
var address = "Mike Address"; var new_address = address+", UK "; console.log(new_address);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.