开发者

Passing javascript objects as function arguments

I want to pass a javascript object (JSON) as an argument to another function. But i am getting foll开发者_C百科owing error:

missing ] after element list

the function is called on onclick event of href like

"<a href='javascript:void(0);' onclick='javascript:openTab("+ sTab +");'>"+ sTab['SavedTab']['title'] +"</a><br/>";

When i pass whole value : sTab['SavedTab']['title'] , it works fine but i want to pass whole object, not just single value out of it.

Please help me out. Thanks.


This is because 'javascript:openTab("+ sTab +");', here sTab is a collection and the script cannot do anything for this collection. You would probably have to pass an index as "sTab['SavedTab']['title']"


I believe if your get sTab not as parameter but as variable inside your js function it will work. 'javascript:openTab();'

javascript:openTab(){
   //sTab as global variable will be accessible here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜