【发布时间】:2013-06-12 16:52:01
【问题描述】:
如果我有这样的代码,带有引号和作者,我怎样才能得到两个 input type="text" 框,我可以在其中写例如两个名称,然后将名称显示在引号中以代替“(随机用户)” ?
//store the quotations in arrays
quotes = [];
authors = [];
quotes[0] = "(randomuser) example (randomuser) example?";
authors[0] = "Authors!";
quotes[1] = "(random user) example (random user) example?";
authors[1] = "Authors!";
//calculate a random index
index = Math.floor(Math.random() * quotes.length);
//display the quotation
document.write("<DL>\n");
document.write("<DT>" + "\"" + quotes[index] + "\"\n");
document.write("<DD>" + " " + authors[index] + "\n");
document.write("</DL>\n");
//done
【问题讨论】:
-
尽量避免使用
document.write -
是否允许用勺子喂食?
-
@AtifMohammedAmeenuddin :由于 OP 正在学习
JS,我认为这是允许的 :) 但我在这里可能是错的 -
@harsha 你能写一些快速的例子吗? :)
-
您想用
authors数组中的名称替换字符串中的(randomuser)?
标签: javascript input quotes