Hello stackovlerflow,
function delete() {
if ($.('#deleted').value=="0") {
$.("#deleted").val('1');
$.("#deletedBtn").removeClass('btn-danger');
$.("#deletedBtn").addClass('btn-success');
$.("#deletedBtn").html("Delete user");
} else {
$.("#deleted").val('0');
$.("#deletedBtn").removeClass('btn-success');
$.("#deletedBtn").addClass('btn-danger');
$.("#deletedBtn").html("Revoke deletion");
}
}
Tis功能让我失望
SyntaxError:function语句需要名称functions.js:1:9
谷歌没有帮助,所以我希望你能帮助我!
非常感谢 // Cripi
答案 0 :(得分:2)
删除是JavaScript中的保留字 - 请参阅List of reserved words in JavaScript
您的代码可能如下所示:
function fun() {
var deleted = $("#deleted");
var deletedBtn = $("#deletedBtn");
if (deleted.val() === "0") {
deleted.val('1');
deletedBtn.removeClass('btn-danger');
deletedBtn.addClass('btn-success');
deletedBtn.html("Delete user");
} else {
deleted.val('0');
deletedBtn.removeClass('btn-success');
deletedBtn.addClass('btn-danger');
deletedBtn.html("Revoke deletion");
}
}
答案 1 :(得分:0)
您不能将delete用作方法名称,因为它是在javascript中保留的。
此外,您可能希望使用变量来避免代码中出现重复:
function deleteAction() {
$btn = $('#deleted');
if ($btn.value=="0") {
$btn.val('1');
$btn.html("Delete user");
} else {
$btn.val('0');
$btn.html("Revoke deletion");
}
$btn.toggleClass("btn-danger btn-success");
}