gpt4 book ai didi

javascript - Uncaught Error 意外标记 (

转载 作者:行者123 更新时间:2023-11-30 17:32:42 25 4
gpt4 key购买 nike

我收到一个错误 Uncaught error uncaught error uncaught token ( in script tag on string with for loop

<script type="text/javascript">
var offer_foto_index = 'slide_offer_preview_1';
var slide_offer_preview_ = [];
var photo_array = <%= @photos.to_json.html_safe %>;
var offer_foto = {
for(var i = 0; i < <%= @photos.length %>; i++) {
slide_offer_preview_[i] = photo_array[i];
}
}
</script>

我需要一个 offer_photo 变量,它应该包含数组 slide_offer_preview_1slide_offer_preview_2slide_offer_preview_3 等。

我哪里做错了?谢谢!

最佳答案

根据您的评论回答:“...我需要一个 offer_photo 变量。它应该包含 slide_offer_preview_1、slide_offer_preview_2 等数组。”

<script type="text/javascript">
var offer_foto_index = 'slide_offer_preview_1';
var slide_offer_preview_ = [];
var photo_array = <%= @photos.to_json.html_safe %>;
var offer_foto = {};
for(var i = 0; i < <%= @photos.length %>; i++) {
offer_photo['slide_offer_preview_' + i] = photo_array[i];
}
</script>

或者如果您需要它位于“offer_foto”对象中的一个数组中:

var offer_foto = {};
offer_foto.slide_offer_preview_ = [];
for(var i = 0; i < <%= @photos.length %>; i++) {
offer_photo.slide_offer_preview_[0] = photo_array[i];
}

关于javascript - Uncaught Error 意外标记 (,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22658728/

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