gpt4 book ai didi

javascript - Laravel Blade : Parse error: syntax error, 意外 ':' ,预期 '('

转载 作者:行者123 更新时间:2023-12-03 04:41:49 25 4
gpt4 key购买 nike

我正在尝试使用 laravel 在 if 语句中运行 javascript 函数,但在尝试这样做时收到以下错误:

Parse error: syntax error, unexpected ':', expecting '(' (View: C:\rcms_w\resources\views\frontend\home.blade.php)

代码:

<script type="text/javascript">
@if (Auth::user()->roleplay->health_points >= 100)
setHealth(1);
@elseif
setHealth(0.{{ Auth::user()->roleplay->health_points }});
@endif

@if (Auth::user()->roleplay->energy_points >= 100)
setEnergy(1, {{ Auth::user()->roleplay->energy_points }});
@elseif
setEnergy(0.{{ Auth::user()->roleplay->energy_points }}, {{ Auth::user()->roleplay->energy_points }});
@endif

@if (Auth::user()->roleplay->hygiene_points >= 100)
setHygiene(1, {{ Auth::user()->roleplay->hygiene_points }});
@elseif
setHygiene(0.{{ Auth::user()->roleplay->hygiene_points }}, {{ Auth::user()->roleplay->hygiene_points }});
@endif

@if (Auth::user()->roleplay->hunger_points >= 100)
setHunger(1, {{ Auth::user()->roleplay->hunger_points }});
@elseif
setHunger(0.{{ Auth::user()->roleplay->hunger_points }}, {{ Auth::user()->roleplay->hunger_points }});
@endif
</script>

最佳答案

您使用此结构:

@if (Auth::user()->roleplay->health_points >= 100) 
setHealth(1);
@elseif
setHealth(0.{{ Auth::user()->roleplay->health_points }});
@endif

被解析为

<?php if (Auth::user()->roleplay->health_points >= 100) : ?>
setHealth(1);
<?php elseif: ?>
setHealth(0.{{ Auth::user()->roleplay->health_points }});
<?php endif; ?>

elseif 部分需要另一个语句(比较某些内容或期望 bool 值)。

如果将 @elseif 更改为 @else,它应该可以工作。

您的新脚本将是这样的:

<script type="text/javascript">
@if (Auth::user()->roleplay->health_points >= 100)
setHealth(1);
@else
setHealth(0.{{ Auth::user()->roleplay->health_points }});
@endif

@if (Auth::user()->roleplay->energy_points >= 100)
setEnergy(1, {{ Auth::user()->roleplay->energy_points }});
@else
setEnergy(0.{{ Auth::user()->roleplay->energy_points }}, {{ Auth::user()->roleplay->energy_points }});
@endif

@if (Auth::user()->roleplay->hygiene_points >= 100)
setHygiene(1, {{ Auth::user()->roleplay->hygiene_points }});
@else
setHygiene(0.{{ Auth::user()->roleplay->hygiene_points }}, {{ Auth::user()->roleplay->hygiene_points }});
@endif

@if (Auth::user()->roleplay->hunger_points >= 100)
setHunger(1, {{ Auth::user()->roleplay->hunger_points }});
@else
setHunger(0.{{ Auth::user()->roleplay->hunger_points }}, {{ Auth::user()->roleplay->hunger_points }});
@endif
</script>

关于javascript - Laravel Blade : Parse error: syntax error, 意外 ':' ,预期 '(',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43054094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com