用JS动态更改字符串? [英] Dynamically change string with JS?

查看:43
本文介绍了用JS动态更改字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的表单需要传递一个隐藏字段:

I'm using a form that needs to pass a hidden field:

<script type="text/javascript">
    var ss_form = {'account': 'XXXXX', 'formID': 'XXXXX'};
    ss_form.width = '100%';
    ss_form.height = '500';
    ss_form.domain = 'app-XXXXX.marketingautomation.services';
    ss_form.hidden = {'field_XXXXX': 'test item, another item' }; 
</script>

所需要的只是一个逗号分隔的列表,但是我试图使用外部按钮(例如,单击)动态添加逗号分隔的项目.

All it needs to be is a comma separated list, but I'm trying to dynamically add comma separated items using external buttons, for example clicking:

<button>add this string</button>

会做到

ss_form.hidden = {'field_XXXXX': 'test item, another item, add this string' }; 

我尝试过使用append到div,然后使用innerHTML作为变量,但是它只是从页面加载而不是动态添加的项目传递初始div内容.JS不是我的强项...非常感谢您的帮助.谢谢!

I've tried using append to a div and then using innerHTML as a variable but it's just passing the initial div content from page load rather than the dynamically added items as well. JS is not my strong suit... any help is very much appreciated. Thank you!

推荐答案

看起来像您想要这样的东西:

Looks like you want something like this:

<button id="button">add this string</button>

document.getElementById("button").onclick = function(event) {
  ss_form.hidden.field_XXXXX += ' ' + this.innerHTML;
}

这篇关于用JS动态更改字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆