如何将javascript指定为php变量中的字符串?
我的代码写在下面:如何将javascript指定为php变量中的字符串?,javascript,php,Javascript,Php,我的代码写在下面: <?php $message = "<script type="text/javascript"> $(document).ready(function(){ demo.initChartist(); $.notify({ icon: 'pe-7s-gift', message: "hello world."
<?php
$message = "<script type="text/javascript">
$(document).ready(function(){
demo.initChartist();
$.notify({
icon: 'pe-7s-gift',
message: "hello world."
},{
type: 'info',
timer: 4000
});
});
</script>";
?>
只需将内部的“
双引号替换为单引号”
<?php
$message = "<script type='text/javascript'>
$(document).ready(function(){
demo.initChartist();
$.notify({
icon: 'pe-7s-gift',
message: 'hello world.'
},{
type: 'info',
timer: 4000
});
});
</script>";
?>
如果您试图将
元素回送到网页上,这应该会起作用
唯一会妨碍您的是引号的使用。现在,您正试图在由双引号组成的字符串中使用双引号。这只有在对字符串中的引号进行转义时才会起作用(可以使用转义字符\
如so“\\”
)
当然,也可以用单引号代替双引号
请看一个更广泛的例子/解释。不必担心引号的最佳方法是使用herdoc
您可以这样做:
$message = <<<JS
$(document).ready(function(){
demo.initChartist();
$.notify({
icon: 'pe-7s-gift',
message: 'hello world.'
},{
type: 'info',
timer: 4000
});
});
JS;
print '<script>'.$message.'</script>';
$message=在解决了引号问题后,您是否尝试将内的双引号替换为”
单引号,并尝试在双引号内使用双引号,例如,双引号下的单引号或单引号下的双引号。我想请人解释否决票?
$message = <<<JS
$(document).ready(function(){
demo.initChartist();
$.notify({
icon: 'pe-7s-gift',
message: 'hello world.'
},{
type: 'info',
timer: 4000
});
});
JS;
print '<script>'.$message.'</script>';