字符串是存储字符(比如 "Bill Gates")的变量。字符串可以是引号中的任意文本。可以使用单引号或双引号。请在预置代码中编写Javascript代码,使预览页面显示如下内容:It's alright
He is called 'Bill'
He is called "Bill"注:可以在字符串内使用引号,只要这些引号与包围字符串的引号不匹配任务与要求请定义字符串变量str1,使用双引号,赋值It's all right请定义字符串变量str2,使用双引号,赋值He is called 'Bill'请定义字符串变量str3,使用单引号,赋值He is called "Bill"请使用document.getElementById(id)方法,并结合br换行标签,使id为demo的段落分行显示3个变量值<!DOCTYPE html><html><body><p id="demo"></p><script></script></body></html>
1 回答
已采纳
莲_蓶濏__
TA贡献25条经验 获得超3个赞
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <p id="demo"></p> <script> for (var i = 1, str1 = "It's all right", str2 = "He is called 'Bill'", str3 = 'He is called "Bill"', oIdDmo = document.getElementById('demo'); i <= 3; i++) oIdDmo.innerHTML += window['str' + i] + '<br />'; </script> </body> </html>
添加回答
举报
0/150
提交
取消