我可以将以下javascript变量设为多行吗?
var newPage = $('<div data-role="page" id="link'+myvar+'" data-url="link'+myvar+'"><div data-role="header" data-position="fixed"><a href="#" data-rel="back" data-icon="back">Back</a></div><iframe src="http://docs.google.com/viewer?embedded=true&url=http://www.example.com'+myarrayA[myvar]+'" style="border: 0; position:absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%; background: white"></iframe></div>');
答案 0 :(得分:3)
有些方法可以在js中模拟多行字符串:
var string = "first line " +
"second line " +
//...
"nth line";
var string = ["first line ",
"second line ",
//...
"nth line"].join('');
var string = "first line \
second line \
//...
nth line";
我个人喜欢 join方法,因为它是有效的javascript,并且您可以在行之间插入字符。例如,如果您想将导出您的字符串作为多行html段落,您可以轻松地像这样做:
var pContent = ["first line ",
"second line "].join('<br>');
答案 1 :(得分:0)
是的,你可以!
var a = $('<div data-role="page" id="link'
+myvar+'" data-url="link'+myvar+'"><div data-role="header" \
data-position="fixed"><a href="#" data-rel="back" \
data-icon="back">Back</a></div> \
<iframe src="http://docs.google.com/viewer? /embedded=true&url=http://www.example.com'
+myarrayA[myvar]+'" style="border: 0; position:absolute; \
top:0; left:0; right:0; bottom:0; width:100%; height:100%; \
background: white"></iframe></div>');
答案 2 :(得分:0)
...是
var newPage = $('<div data-role="page" id="link'+myvar+'" data-url="link'+myvar+'">' +
' <div data-role="header" data-position="fixed">' +
' <a href="#" data-rel="back" data-icon="back">Back</a>' +
' </div>' +
' <iframe src="http://docs.google.com/viewer?embedded=true&url=http://www.example.com'+myarrayA[myvar]+'" style="border: 0; position:absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%; background: white"></iframe>' +
'</div>');