我想评论一个代码块,但我的 javascript block 中有一行包含 jquery 和 php
像这样
jq('.time_slot').each(function(index) {
var a = jq(this).autocomplete({
serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",
params: { suggessions_id:28767 }, //aditional parameters
onSelect:function(value,data){ jq(this).trigger('change'); }
});
});
没有这行
serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",
我可以使用
评论这个 block/*
*/
但现在我不能使用它,我也尝试过使用单行注释,就像这样
//jq('.time_slot').each(function(index) {
//var a = jq(this).autocomplete({
//serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",
// params: { suggessions_id:28767 }, //aditional parameters
// onSelect:function(value,data){ jq(this).trigger('change'); }
// });
// });
但是对于这一行
serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",
它不工作。
所以我最终得到了一个像这样的非常普通的解决方案
//serviceUrl:"
<? //echo $this->config->item('base_url'); ?>
//business/information/add/autocomplete",
注释我的代码块的最佳方式是什么,提前谢谢您。
最佳答案
在运行时,如果启用了 php 配置的 Short_open_tag,则这些脚本包含在 <? ?>
中在将 html(包含带注释的上述 javascript)发送到浏览器之前,服务器中的 php 解析器会对其进行解析。
因此,如果您使用//注释掉该行,从技术上讲应该可以工作,因为 javascript 解析器不会知道该字符串是从 php 生成的。
确保您启用了short_open_tag或使用<?php
而不是短标签 (<?)
.
关于php - 如何注释jquery中包含一行php代码的jquery代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9495405/