[英]Naming an element inside javascript
I want the select name array keys have a quotations inside.我希望选择名称数组键里面有引号。 But this one doesn't generate quotations inside the brackets.
但是这个不会在括号内生成引号。 How can I achieve it?
我怎样才能实现它?
var id = "test";
var element = "<select name = 'unit_id["+id+"]' class = 'form-control'></select>";
You can use Template literals which is more cleaner.您可以使用更简洁的模板文字。 This does not require string concatenation and character escaping:
这不需要字符串连接和字符转义:
var id = "test"; var element = `<select name = 'unit_id["${id}"]' class = 'form-control'></select>`; console.log(element)
Like this:像这样:
var id = "test"; var elemnt = "<select name=\\"unit_id['" + id + "']\\" class=\\"form-control\\"></select>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.