按钮不调用函数
Button not calling function
我们试图在单击按钮时调用一个函数,但由于某种原因按钮不会调用该函数。谁能告诉我们为什么?
<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>
试试吧,这对你有帮助。
函数中存在语法错误。
<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 点击功能的右括号丢失,这就是点击事件未触发的原因
您的 instagramclick() 函数缺少右大括号。
我们试图在单击按钮时调用一个函数,但由于某种原因按钮不会调用该函数。谁能告诉我们为什么?
<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>
试试吧,这对你有帮助。 函数中存在语法错误。
<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 点击功能的右括号丢失,这就是点击事件未触发的原因
您的 instagramclick() 函数缺少右大括号。