我有以下初始化对象,我想通过onclick函数传递这个对象,这可以实现吗?
var nameObject = { Name: "Stack", lastName:"Exchange" }
这是我的代码:
在document ready
我有与附加到html元素中的函数的链接。onclick
html:
<div id="test"></div>
Javascript:
$(document).ready(function () {
var nameObject = { Name: "Stack", lastName:"Exchange" };
$("#test").append('<a href="#"'
+'onclick="sendObj(**I want to pass "nameObject" into this function)">'
+'sendObject</a>');
)};
function sendObj(**receive the object**)
{
//nameObject.Name+" "nameObject.lastName;
}