最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to comment a jquery code block which has a line with php code in jquery - Stack Overflow

programmeradmin0浏览0评论

i want to ment a code block, but i have a line in my javascript block which has jquery and php both

like this

jq('.time_slot').each(function(index) {
    var a = jq(this).autoplete({ 
        serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",
        params: { suggessions_id:28767 }, //aditional parameters
        onSelect:function(value,data){ jq(this).trigger('change');  } 
    });
});

with out this line

      serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",

i can ment this block using

/*

*/

but now i can not use it , also i tried with single line ments , like this

//jq('.time_slot').each(function(index) {
    //var a = jq(this).autoplete({ 
        //serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",
       // params: { suggessions_id:28767 }, //aditional parameters
       // onSelect:function(value,data){ jq(this).trigger('change');  } 
   // });
   // });

but for this line

 serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",

it is not working .

so i ended up with a very odinary solution like this

 //serviceUrl:"
<? //echo $this->config->item('base_url'); ?>
//business/information/add/autoplete",

what is the best way to ment my code block , thank you in advance .

i want to ment a code block, but i have a line in my javascript block which has jquery and php both

like this

jq('.time_slot').each(function(index) {
    var a = jq(this).autoplete({ 
        serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",
        params: { suggessions_id:28767 }, //aditional parameters
        onSelect:function(value,data){ jq(this).trigger('change');  } 
    });
});

with out this line

      serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",

i can ment this block using

/*

*/

but now i can not use it , also i tried with single line ments , like this

//jq('.time_slot').each(function(index) {
    //var a = jq(this).autoplete({ 
        //serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",
       // params: { suggessions_id:28767 }, //aditional parameters
       // onSelect:function(value,data){ jq(this).trigger('change');  } 
   // });
   // });

but for this line

 serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",

it is not working .

so i ended up with a very odinary solution like this

 //serviceUrl:"
<? //echo $this->config->item('base_url'); ?>
//business/information/add/autoplete",

what is the best way to ment my code block , thank you in advance .

Share Improve this question asked Feb 29, 2012 at 7:54 Kanishka PanamaldeniyaKanishka Panamaldeniya 17.6k31 gold badges127 silver badges194 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

On runtime, if your php configuration's short_open_tag is enabled, those script enclosed in <? ?> would have been parsed by php parser in the server before sending the html (that contains the said javascript with ment) to the browser.

So it should technically work if you use // to ment out that line, as the javascript parser won't be aware that the string was generated from php.

Make sure you have short_open_tag enabled or use <?php instead of short tags (<?).

Ok, admittedly, this isn't pretty, but if you want to cancel out the mingled PHP and JavaScript in one fell swoop, you might consider wrapping the entire block in a PHP condition that always returns false, e.g:

<?php if (1 == 0) { ?>
jq('.time_slot').each(function(index) {
    var a = jq(this).autoplete({ 
        serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autoplete",
        params: { suggessions_id:28767 }, //aditional parameters
        onSelect:function(value,data){ jq(this).trigger('change');  } 
    });
});
<?php } ?>

Ugly, I know, but undeniably quick and effective for big blocks of mixed code.

Afaik theres no better solution that you provided. PHP and JS ments are always separate, you can put JS ment into PHP's echo function.

PHP parser will always try to run code between blocks.

Imho best solution is to ment whole JS code using /* and */ and use single line ment to prevent PHP running php code block.

That is the best way already. Can't think of any better ways..

发布评论

评论列表(0)

  1. 暂无评论