gpt4 book ai didi

javascript - 在javascript中传递对象

转载 作者:行者123 更新时间:2023-11-29 22:27:49 26 4
gpt4 key购买 nike

我想在 javascript 中传递一个对象。但是我收到一个错误 javascript:callbackCredits(1,dotsContainer_credits);未定义

我的代码如下:

var dotSlideCredits = {
show : 3,
width : 430,
functionName : "callbackCredits",
title: "title",
itemId: "#s_credit"
}

var test = {
data[]
}

$(document).ready(function(){
dynamicList(dotSlideCredits);
}

function dynamicList(dotSlide){
var divItems = "dotsContainer_"+dotSlide.title;
test.data.push({title: dotSlide.title+[i], callBack: "javascript:"+dotSlide.functionName+"("+i+","+divItems+");"});
}


function callbackCredits(current, container){
var prev = $("#previousCredit").val();
slideShow(current, prev, container);
$("#previousCredit").attr("value", current);
}

最佳答案

我会做的可能是这样的:

var dotSlideCredits = { 
show : 3,
width : 430,
itemId: "#s_credit",
functionName: function(current, container){
callbackCredits(current,container);
}
}

函数 callbackCredits(当前,容器){ var prev = $("#previousCredit").val();
slideShow(当前,上一个,容器);
$("#previousCredit").attr("value", current);

然后只需调用 dotSlide.functionName(i,divItems);

(未经测试的回合应该接近那个)

关于javascript - 在javascript中传递对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8487509/

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