Javascript 为什么不是';这不是用单选按钮值中的整个字符串替换吗?
我正在使用.replaceWith()使用数组更改单选按钮的值:Javascript 为什么不是';这不是用单选按钮值中的整个字符串替换吗?,javascript,jquery,Javascript,Jquery,我正在使用.replaceWith()使用数组更改单选按钮的值: $("#choice1").replaceWith("<li id = 'choice1'>" + "<input type='radio' >name='choice' value="+allQuestions[currentTurn].possibleAnswers[0]+">"+allQuestions[currentTurn].>possibleAnswers[0] "</li&g
$("#choice1").replaceWith("<li id = 'choice1'>" + "<input type='radio' >name='choice' value="+allQuestions[currentTurn].possibleAnswers[0]+">"+allQuestions[currentTurn].>possibleAnswers[0] "</li>");
$(“#choice1”)。替换为(“”+“name='choice”value=“+allQuestions[currentTurn]。possibleAnswers[0]+“>”+allQuestions[currentTurn]。>possibleAnswers[0]” ”;
当我有一个字符串(例如“最后一场战斗”)时,第一个+allQuestions[currentTurn].possibleAnswers[0]
只返回字符串的第一个单词,而同一个代码第二次返回整个字符串
有人能告诉我为什么吗?如何使它们都返回整个字符串
谢谢 如果属性值包含空格,则需要在其周围加引号
$("#choice1").replaceWith("<li id = 'choice1'>" +
"<input type='radio' name='choice' value='" +
allQuestions[currentTurn].possibleAnswers[0] +
"'>" +
allQuestions[currentTurn].>possibleAnswers[0] "</li>");
$(“#choice1”)。替换为(“”+
"" +
所有问题[currentTurn]。>可能的回答[0]“ ”;
否则,您的HTML将如下所示:
<input type='radio' value=The Last Battle>
从中可以看出,值只是
the
,而Last
和Battle
看起来像是附加属性(因此,语法高亮显示甚至可以清楚地表明这一点)。在name
之前的
不在实际代码中,是吗?