我正在使用.replaceWith()来使用数组更改单选按钮的值:
$("#choice1").replaceWith("<li id = 'choice1'>" + "<input type='radio' >name='choice' value="+allQuestions[currentTurn].possibleAnswers[0]+">"+allQuestions[currentTurn].>possibleAnswers[0] "</li>");
当我有一个字符串(例如“ The Last Battle”)时,第一个+allQuestions[currentTurn].possibleAnswers[0]
仅返回字符串的第一个单词,第二次,相同的代码返回整个字符串。
有人可以告诉我为什么吗?以及如何使它们都返回整个字符串?
谢谢!
如果属性值包含空格,则需要在属性值两边加上引号。
$("#choice1").replaceWith("<li id = 'choice1'>" +
"<input type='radio' name='choice' value='" +
allQuestions[currentTurn].possibleAnswers[0] +
"'>" +
allQuestions[currentTurn].>possibleAnswers[0] "</li>");
否则,您的HTML将如下所示:
<input type='radio' value=The Last Battle>
正如你可以从看到,该值仅是The
,虽然Last
和Battle
样子附加属性(SO的语法高亮甚至使说清楚)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句