我们试图在按钮点击时调用一个函数,但由于某种原因,该按钮不会调用该函数。谁能告诉我们为什么?
<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>
答案 0 :(得分:1)
试试这会对你有所帮助。 函数中存在语法错误。
<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>
答案 1 :(得分:0)
instagramclick functionn的关闭括号缺少这就是为什么点击事件没有解雇
答案 2 :(得分:0)
您缺少instagramclick()函数上的紧密括号。