小编Alm*_*tas的帖子

Javascript:无法在 Else 上读取 null 的属性“样式”

错误消息: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 …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

html ×1

javascript ×1

jquery ×1