【发布时间】:2016-02-02 11:01:53
【问题描述】:
所以我通过 Google 和 Stackoverflow 进行了搜索,但对于我的生活,我似乎无法找到为什么我会收到带有此代码的“[object Object]”警告框。我根本不明白我为什么会这样。我的代码的哪一部分使该警报发生?
<script type="text/javascript" src="jquery.min.js"></script>
<style>
#circle{
background-color: green;
width:200px;
height:200px;
border-radius: 100px;
}
.square{
background-color: red;
width:300px;
height:300px;
margin-top: 10px;
}
</style>
</head>
<body>
<div id="circle"></div>
<div class="square"></div>
<div class="square"></div>
<script>
$("div").click(function(){
alert($(this).css("width","400px"));
});
</script>
</body>
【问题讨论】:
-
那你想提醒什么?
-
因为每个 jQuery 函数都返回他自己的实例(= 以“return this”结尾以便被链接。所以你的函数与 :alert(this) 或 this 是一个对象一样。所以你得到 [object Object]
标签: javascript jquery html css object