显示带引号的 Javascript 变量

我有一个变量,它是重复列表的一部分,当我使用 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。我尝试在引号前添加斜杠,但是毫无喜悦。


慕莱坞森
浏览 56回答 1
1回答

aluckdog

使用该escape()功能。你可以这样使用它escape(tempDesc):这里需要它,因为您必须转义引号才能将其像普通字符一样进行归档,而不是像下面这样作为引用字符串的结尾:“这个字符串在“引号”中,但其中仍然有引号”。"this String is in \"quotes\" but still has quotes in it".
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript