Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按钮不调用函数_Javascript_Html_Button - Fatal编程技术网

Javascript 按钮不调用函数

Javascript 按钮不调用函数,javascript,html,button,Javascript,Html,Button,我们试图在单击按钮时调用函数,但由于某些原因,该按钮不会调用该函数。有人能告诉我们为什么吗 <body> <button onclick="instagramclick()">Login to instagram</button> <button onclick="myFunction()">Test Button</button> <script> function myFunction() { alert("

我们试图在单击按钮时调用函数,但由于某些原因,该按钮不会调用该函数。有人能告诉我们为什么吗

<body>

<button onclick="instagramclick()">Login to instagram</button>
<button onclick="myFunction()">Test Button</button>

<script>
function myFunction() {
    alert("Hello World");
}

function instagramclick(){
    alert("button clicked");
    window.location.href = "https://instagram.com/oauth/authorize/?client_id=8a612cd650344523808233c0468c80ed&redirect_uri=http://u-ahmed.github.io/HookedUp/&response_type=token";
    var token = window.location.href.substring(43);

    if(token="s_denied&error_reason=user_denied&error_description=The+user+denied+your+request"){
    alert("That's fine, but we can't access your instagram without your permission.");
    }
    else {
    jQuery(function($) {

        function writeToFile(token){
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var fh = fso.OpenTextFile("D:\\instagramtoken.txt");
            fh.WriteLine(", ,"+ token);
            fh.Close();
        }
    });

}
</script>

</body>

登录instagram
测试按钮
函数myFunction(){
警报(“你好世界”);
}
函数instagramclick(){
警报(“点击按钮”);
window.location.href=”https://instagram.com/oauth/authorize/?client_id=8a612cd650344523808233c0468c80ed&redirect_uri=http://u-ahmed.github.io/HookedUp/&response_type=token”;
var token=window.location.href.substring(43);
if(token=“s\u denied&error\u reason=user\u denied&error\u description=The+user+denied+your+请求”){
提醒(“这很好,但未经您允许,我们无法访问您的instagram。”);
}
否则{
jQuery(函数($){
函数writeToFile(令牌){
var fso=新的ActiveXObject(“Scripting.FileSystemObject”);
var fh=fso.OpenTextFile(“D:\\instagramtoken.txt”);
fh.写入线(“,”+令牌);
fh.Close();
}
});
}

试试看这会对你有所帮助。 函数中存在语法错误


登录instagram
测试按钮
函数myFunction(){
警报(“你好世界”);
}
函数instagramclick(){
警报(“点击按钮”);
window.location.href=”https://instagram.com/oauth/authorize/?client_id=8a612cd650344523808233c0468c80ed&redirect_uri=http://u-ahmed.github.io/HookedUp/&response_type=token”;
var token=window.location.href.substring(43);
if(token=“s\u denied&error\u reason=user\u denied&error\u description=The+user+denied+your+请求”){
提醒(“这很好,但未经您允许,我们无法访问您的instagram。”);
}否则{
jQuery(函数($){
函数writeToFile(令牌){
var fso=新的ActiveXObject(“Scripting.FileSystemObject”);
var fh=fso.OpenTextFile(“D:\\instagramtoken.txt”);
fh.写入线(“,”+令牌);
fh.Close();
}
});
}
}

instagramclick函数的右括号缺失,这就是为什么click事件没有触发的原因

您缺少instagramclick()函数上的右括号。

用大括号关闭instagramclick函数非常感谢,我们真的松了一口气。