0

これが私の要件です、私は次のような日付ごとのデータを持つ配列を持っています

$.each(dateWiseArr, function(index, currentDate){
    myDateArray[currentDate] = "myData";
    dateWiseOtherId[currentDate] = "otherId";
});
alert(myDateArray+"::"+dateWiseOtherId);//working fine and showing right data
$("#myBtn").attr("onClick", "myPassingFunction("+myDateArray+", "+dateWiseOtherId+")");

function myPassingFunction(myDateArray, dateWiseOtherId){
    alert(myDateArray[0]);//throw undefined
}

ボタンを押すと、関数呼び出しは正常に実行されますが、変数は文字列になります。

さらに理解が必要な場合はお知らせください。

注:myDate

4

3 に答える 3

1

文字列をバインドする代わりに関数をバインドすると、値を文字列に変換する必要がなくなります。

$("#myBtn").click(function(){
  myPassingFunction(myDateArray, dateWiseOtherId);
});
于 2012-11-07T12:46:05.550 に答える
1

以下で試してみてください。それはうまくいくはずです。

$.each(dateWiseArr, function(index, currentDate){
    myDateArray[currentDate] = "myData";
    dateWiseOtherId[currentDate] = "otherId";
});

alert(myDateArray+"::"+dateWiseOtherId);//working fine and showing right data

$("#myBtn").click(function (event) {
     myPassingFunction(myDateArray, dateWiseOtherId);
});

function myPassingFunction(myDateArray, dateWiseOtherId){
    alert(myDateArray[0]);//throw undefined
}
于 2012-11-07T12:49:08.633 に答える
0

イベントをバインドする正しい方法: この作業フィドルを確認してくださいhttp://jsfiddle.net/vC4Yk/

var myDateArray = ["some data"];
var dateWiseOtherId = ["some other data"];

alert(myDateArray+"::"+dateWiseOtherId);//working fine and showing right data

$("#myBtn").click(function(){
   myPassingFunction(myDateArray, dateWiseOtherId);      
});

function myPassingFunction(myDateArray, dateWiseOtherId){
    alert(myDateArray[0]);
}   ​
于 2012-11-07T12:55:44.990 に答える