开发者

Passing javascript objects as function arguments

开发者 https://www.devze.com 2022-12-22 21:06 出处:网络
I want to pass a javascript object (JSON) as an argument to another function. But i am getting foll开发者_C百科owing error:

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

精彩评论

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

关注公众号