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函数非常感谢,我们真的松了一口气。