在javascript中使用php函数

ghhaqwfi  于 2021-06-19  发布在  Mysql
关注(0)|答案(2)|浏览(302)
<script>
  $(document).ready(function () {
    var oMain = new CMain({
      win_occurrence: 40, //WIN PERCENTAGE.SET A VALUE FROM 0 TO 100.
      slot_cash: 200, //THIS IS THE CURRENT SLOT CASH AMOUNT. THE GAME CHECKS IF THERE IS AVAILABLE CASH FOR WINNINGS.
      bonus_occurrence: 15, //SET BONUS OCCURRENCE PERCENTAGE IF PLAYER GET A WIN. SET A VALUE FROM 0 TO 100. (IF 100%, PLAYER GET A BONUS EVERYTIME THERE IS A WIN).
      min_reel_loop: 1, //NUMBER OF REEL LOOPS BEFORE SLOT STOPS  
      reel_delay: 0, //NUMBER OF FRAMES TO DELAY THE REELS THAT START AFTER THE FIRST ONE
      time_show_win: 2000, //DURATION IN MILLISECONDS OF THE WINNING COMBO SHOWING
      time_show_all_wins: 2000, //DURATION IN MILLISECONDS OF ALL WINNING COMBO
      money: <?php $kullanici_bilgileri->bakiye ?>, //STARING CREDIT FOR THE USER
      min_bet: 0.05, //MINIMUM COIN FOR BET
      max_bet: 0.5, //MAXIMUM COIN FOR BET
      max_hold: 3, //MAXIMUM NUMBER OF POSSIBLE HOLD ON REELS
      perc_win_prize_1: 50, //OCCURENCE PERCENTAGE FOR PRIZE 1 IN BONUS
      perc_win_prize_2: 35, //OCCURENCE PERCENTAGE FOR PRIZE 2 IN BONUS
      perc_win_prize_3: 15, //OCCURENCE PERCENTAGE FOR PRIZE 3 IN BONUS
      num_symbol_bonus: 3, //NUMBER OF BONUS SYMBOLS (DEFAULT IS SYMBOL 9) THAT MUST BE SHOWN TO ACHIEVE THE BONUS PANEL
      num_spin_ads_showing: 10 //NUMBER OF SPIN TO COMPLETE, BEFORE TRIGGERING AD SHOWING.
      //// THIS FUNCTIONALITY IS ACTIVATED ONLY WITH CTL ARCADE PLUGIN.///////////////////////////
      /////////////////// YOU CAN GET IT AT: /////////////////////////////////////////////////////////
      // http://codecanyon.net/item/ctl-arcade-wordpress-plugin/13856421 ///////////
    });
</script>

你好,这是我想在这个javascript中使用php函数的代码。

money: <?php $kullanici_bilgileri->bakiye ?>

我是这样写的,但那不适合我。

0sgqnhkj

0sgqnhkj1#

要用php打印任何文本,应该使用 echo 或者 print 功能。所以这一行:

<?php $kullanici_bilgileri->bakiye ?>

应该是:

<?php echo $kullanici_bilgileri->bakiye; ?>

编辑:据我所知,如果不使用javascript代码中的引号,就不能传递php字符串,否则会出现如下错误
未捕获的语法错误:意外的标识符
因此,请更换:

money: <?php $kullanici_bilgileri->bakiye ?>

有了这个:

money: '<?php echo $kullanici_bilgileri->bakiye; ?>',
fjnneemd

fjnneemd2#

正如@variable所指出的。如果你想输出一个字符串,你需要在它周围加引号。
另一种在js中使用适当类型转换的方法是 json_encode ,示例:

{
    ...
    money: <?php echo json_encode($kullanici_bilgileri->bakiye) ?>,
    ...
}

使用这种方法,您不必担心忘记引号。

相关问题