简体   繁体   English

javascript 引号和撇号问题

[英]javascript quotation marks and apostrophes marks issue

its not working when i'm using multiple quotation and apostrophes in javascript.当我在 javascript 中使用多个引号和撇号时,它不起作用。 i'm trying to store javascirpt code in a variable and then want to echo in footer with the concern page.我正在尝试将 javascirpt 代码存储在一个变量中,然后想在关注页面的页脚中回显。 here im trying to create dynamic form which working perfectly but bcoz some error in quotation marks and apostrophes marks its not working.在这里,我试图创建可以完美运行的动态表单,但是由于引号和撇号中的一些错误标志着它无法正常工作。 i tried this code in footer directly it working but i want it the view page to store it in FooterScript and then echo in the footer.我在页脚中直接尝试了这段代码,但我希望它在视图页面中将其存储在 FooterScript 中,然后在页脚中回显。 so in footer script if u see whole code is insode the apostrophe.因此,如果您在页脚脚本中看到整个代码都包含撇号。 so inside one apostrophewe cant use another apostrophe we need to change it to qoutation mark.所以在一个撇号内我们不能使用另一个撇号,我们需要将其更改为 qoutation 标记。 if im changing it to qoutation mark the problem araise here and id="'+i+'" if im changing apostrophes here to qoutation mark then its not working.i dont know how to achieve this如果我将其更改为 qoutation 标记问题在这里出现,并且 id="'+i+'" 如果我将撇号在这里更改为 qoutation 标记,那么它不起作用。我不知道如何实现这一点

body with javascript code带有 javascript 代码的机身

<?php
$this->FooterScript=sprintf('
<script>
$(document).ready(function(){
var i=1;
$("#add").click(function(){
i++;
$("#dynamic_field").append("<tr id="row'+i+'"><td><select name="name[]" id="name[]" class="form-control name_list"><?php foreach($data_l as $data) { ?><option value="<?=$data->id;?>"><?=$data->name;?></option><?php } ?></select></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>");
});
$(document).on("click", ".btn_remove", function(){ var button_id = $(this).attr("id");
$("#row"+button_id+"").remove();
});
});
</script>');
?>

Footer页脚

<?php echo $this->FooterScript; ?>

This is the problem这就是问题

<?php foreach($data_l as $data) { ?><option value="<?=$data->id;?>"><?=$data->name;?></option><?php } ?>

PHP script inside a string, won't be executed.字符串中的 PHP 脚本,不会被执行。 First process the above string and then attach it to the FooterScript先处理上面的字符串,然后附加到FooterScript

Edit Add \ before the quotation mark that you want to escape Ex: "\"" The second " will be escaped.编辑在要转义的引号前添加\例如: "\""第二个"将被转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM