如何在 Jquery 中进行字符串引号
我如何将变量放在单引号和双引号中我很困惑
var rdb ='<input type="radio" id="rdb_"'+ i +' data-value1='+ labelvalue[1] +' data-value2='+ data[i].value +'>';
t += '<tr><td>'+rdb+'</td><tr>';
这里变量“i”是动态的,“labelvalue[1]”是动态的,“data[i].value”是动态的 因此,我无法生成动态单选按钮。所以查看源代码看起来像这样
我如何使用单引号和双引号正确生成此内容 输入类型=“无线电”id=“rdbacc_0”数据值1=“testRYSTAYTYTAST”数据值=“007”
How do i put the variables in this single quotes and double quotes iam confused
var rdb ='<input type="radio" id="rdb_"'+ i +' data-value1='+ labelvalue[1] +' data-value2='+ data[i].value +'>';
t += '<tr><td>'+rdb+'</td><tr>';
Here variable "i" is dynamic , "labelvalue[1] " is dynamic and "data[i].value " is dynamic
Due to this iam not able to produce the Dynamic Radio buttons . So the View source looks in this way
How do i correctly produce this using single quotes and double quotes
input type="radio" id ="rdbacc_0" data-value1="testRYSTAYTYTAST" data-value="007"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您使用 jQuery,这可能会更好地运行和阅读:
If you are using jQuery this would probably function and read much better:
在大多数情况下,您都很好 - 只是在
id
值后面缺少一个双引号,并在data-value
周围加上引号:最好的做法是选择您将使用的引号(您所做的)的一致选择,在本例中,双引号用于实际标记,单引号用于分隔代码,然后从您想要的结果开始并确保引号是正确的,例如:
然后返回并添加
' + x + '
代替大括号中的位。 (您不必使用大括号,这只是一个示例。)您还可以找到新的 jQuery 模板 插件对这个东西很有用。
For the most part, you were fine — just missing an end-double-quote after the
id
value and quotes around yourdata-value
s:The best thing to do is to pick a consistent choice of which quote you'll use (which you did), in this case double quotes for the actual markup and single quotes to delimit the code, and then start with what you want to end up with and make sure the quotes are correct, so for instance:
Then go back and add
' + x + '
in place of the bits in curly brackets. (You don't have to use curly brackets, that's just an example.)You may also find the new jQuery templates plug-in useful for this stuff.
您可能想用
Array
替换这样的“构造”。这具有更好的可读性,并且在大多数情况下比通过+
进行字符串连接更快。You might want to replace such "constructs" with an
Array
. That has a better readability and in most cases is faster than string concat by+
.你似乎已经快到了,你的一些引言放错了地方
you seem to be almost there, some of your quotes are in the wrong place
这应该可以做到..
this should do it ..
应该这样做
should do it
嗯,这是一些跳出框框的想法。不要让自己陷入如此难以阅读的境地。使用.attr()。
Hmm, here's some thinking outside the box. Don't put yourself in such a difficult to read situation. Use .attr().
您可以在字符串中使用 helo 变量
var helo = "'"+ ok +"'";
或者
直接在字符串中使用它
""" + color + """;
you can use the helo variable in you string
var helo = "'"+ ok +"'";
OR
use this directly in your string
""" + color + """;