我想在javascript中传递一个对象。但我收到错误javascript:callbackCredits(1,dotsContainer_credits); is undefined
我的代码如下:
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);
}
答案 0 :(得分:1)
我会做的事情可能是这样的:
var dotSlideCredits = {
show : 3,
width : 430,
itemId: "#s_credit",
functionName: function(current, container){
callbackCredits(current,container);
}
}
function callbackCredits(current,container){
var prev = $(“#previousCredit”)。val();
slideShow(current,prev,container);
$(“#previousCredit”)。attr(“value”,current);
}
然后只需致电dotSlide.functionName(i,divItems);
(未经测试的回合应该接近那个)
答案 1 :(得分:1)
您确定callBack属性不是函数吗?它应该是
E.g:
test.data.push({
title: dotSlide.title+[i],
callBack: function () {
dotSlide.functionName(i,divItems);
}
});
这有意义吗?
答案 2 :(得分:0)
我认为错误消息非常具有描述性。您已在函数名称中添加了伪造的"javascript:"
前缀。删除它。