Alm*_*tas 2 html javascript jquery
错误消息:Cannot read property 'style' of null 出现在我的“else”语句的第一条语句中。不知道我哪里出错了。有什么想法吗?
$(document).ready(function () {
var foursquareApi = {
clientId: "CLIENT_ID",
clientSecret: "CLIENT_SECRET",
redirectUrl: "http://almontas.github.io/FourSquareJax/"
}
if (access_token === 0) {
document.getElementById('dashboardProfile').style.display == 'none';
document.getElementById('dashboardInfo').style.display == 'none';
$('.connect').click(function () {
var url = "https://foursquare.com/oauth2/access_token";
url += "?client_id=" + foursquareApi.clientId;
url += "&response_type=token";
url += "&redirect_uri=" + foursquareApi.redirectUrl;
window.location = url;
});
} else {
document.getElementById('dashboardProfile').style.display == 'block'; //this lines gives an error message.
document.getElementById('dashboardInfo').style.display == 'block';
}
Run Code Online (Sandbox Code Playgroud)
这是一些有问题的 HTML。如评论所述, .dashboardProfile 和 .dashboardInfo 似乎已经到位。
<body>
<div class="container">
<div class="header">
<div class="logo"><img src = "images/foursquare-logo.png">
</div>
</div>
<div class="dashboard-container">
<div class="dashboardConnect">
<div class="connect"><p> Sign In </p>
</div>
</div>
<div class="dashboardProfile">
<p>User Information and Picture</p>
</div>
<div class="dashboardInfo">
<p>Check Ins </p>
<div class="indicator checkin"> # </div>
<p>Countries</p>
<div class="indicator country"> # </div>
<p>Cities</p>
<div class="indicator city"> # </div>
</div>
</div>
</div><!--container-fluid-->
Run Code Online (Sandbox Code Playgroud)
你没有一个带有 IDdashboardProfile的元素,你有一个带有 class 的元素dashboardProfile。
所以你也是:
document.getElementsByClassName('dashboardProfile')[0].style.display = "none"
Run Code Online (Sandbox Code Playgroud)
您的 otherdocument.getElementById也是如此,您的 HTML 中没有任何带有 ID 的元素。