为了账号安全,请及时绑定邮箱和手机立即绑定

显示带引号的 Javascript 变量

显示带引号的 Javascript 变量

慕莱坞森 2023-10-14 16:15:50
我有一个变量,它是重复列表的一部分,当我使用 console.log 时,可以看到带引号的字符串,但当打印时,会截掉除该列表之外的所有内容。function sendToPackList(){          for(let i = 0; i < $('[name="tempQuant[]"]').length; i++){              if($('[name="tempQuant[]"]')[i].value > 0){                packItem++;                let temprow = $('[name="tempQuant[]"]').eq(i).parent().parent().parent().parent();                let tempDesc = temprow.find('[name="tempDesc[]"]')[0].value                console.log(tempDesc);                let tempWeight = temprow.find('[name="tempWeight[]"]')[0].value                let tempQuant = temprow.find('[name="tempQuant[]"]')[0].value                $('#packlistItems').append('<div class="row"><div class="6u"><div style="position:relative">    <input type="text" name="goodsDesc[]" onkeyup="stockAutocomplete(this)" autocomplete="off" value="'+tempDesc+'"></div></div></div>变量名为 tempDesc 并保存字符串 48" 监视器,并显示为 console.log 语句中的内容。但是,当它达到 value="'+tempDesc'" 时,它仅显示单词 48。我尝试在引号前添加斜杠,但是毫无喜悦。
查看完整描述

1 回答

?
aluckdog

TA贡献1847条经验 获得超7个赞

使用该escape()功能。你可以这样使用它escape(tempDesc):这里需要它,因为您必须转义引号才能将其像普通字符一样进行归档,而不是像下面这样作为引用字符串的结尾:

“这个字符串在“引号”中,但其中仍然有引号”。

"this String is in \"quotes\" but still has quotes in it".


查看完整回答
反对 回复 2023-10-14
  • 1 回答
  • 0 关注
  • 53 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信