在这个例子中,我试图遍历传递给点击处理程序的对象的属性,但我得到了意想不到的结果。 Here's小提琴将对象传递给事件jQuery
所以用JS脚本像
$(document).ready(function()
{
Label = function (name, toDate, fromDate)
{
this.name = name;
this.toDate = toDate;
this.fromDate = fromDate;
}
lbl = new Label('John', 'Today', 'Yesterday');
$('#btnSubmit').click(function()
{
for (var i in lbl)
{
console.log(i);
}
});
$('#btnSubmit2').click(function (Label)
{
for (var i in Label)
{
console.log(i);
}
});
});
我为什么不能传递一个对象在点击事件的功能和遍历其属性,而不是使用forin循环像我一样的在btnSubmit
的例子?
你的编号问题是很难理解的,即使你的全球性问题似乎很清楚。 –
你将如何获得'btnSubmit2'处理程序中的标签?因为你命名变量'Label'?它只是参数名称... – NDM
@dystroy编辑为什么是最紧迫的我。 – wootscootinboogie