开发者

Cannot use php tag in javascript tag

I'm trying开发者_如何学Python to use php tag in a javascript function. But unfortunately its not working. I even used <?php but still not working. I checked php.ini file and there the short tag is already enabled.

Any sort of suggestion will be appreciated.


You should be aware that a php tag inside javascript gets evaluated on the serverside before it gets sent to the client. Example: If the php variable $feeling holds the string "love" "I love cheese." gets alerted.

<script type="text/javascript">
var text = "I <?php echo $feeling;?> cheese";
alert(text);
</script>

In that case the javascript code that gets returned from the server will look like:

<script type="text/javascript">
var text = "I love cheese";
alert(text);
</script>

I hope this will be of help to you to solve your issue.


as you described here, your code should be working. you can use php code in JavaScript with PHP tags() if you are using core php.but its not working in smarty structure. so please mind it and check if you are using any framework or structures.

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜