我正在尝试从一个函数中alert返回的值,并且在弹出框中得到了以下内容:
[object Object]
以下是JavaScript代码:
<script type="text/javascript">
$(function ()
{
var $main = $('#main'),
$1 = $('#1'),
$2 = $('#2');
$2.hide(); // 页面加载时隐藏div#2
$main.click(function ()
{
$1.toggle();
$2.toggle();
});
$('#senddvd').click(function ()
{
alert('hello');
var a=whichIsVisible();
alert(whichIsVisible());
});
function whichIsVisible()
{
if (!$1.is(':hidden')) return $1;
if (!$2.is(':hidden')) return $2;
}
});
</script>
whichIsVisible是我正在尝试检查的函数。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
将对象转换为字符串的默认结果是
"[object Object]"。由于您正在处理jQuery对象,您可能想执行以下操作
以打印元素的ID。
如评论中所提到的,您应该使用Firefox或Chrome等浏览器中包含的工具来检查对象,而不是使用
alert,可以执行console.log(whichIsVisible())。附注:ID不应以数字开头。