按钮:
<button type="submit" id="status" class="button" value="True"><span>followed</span></button>
jQuery:
<script>
$(".button").toggle(function() {
$(this).val('followed');
}, function(){
$(this).val('follow');
});
</script>
当用户单击该按钮时,我希望它切换到另一个值。但是,现在当我运行代码时,该按钮只是从页面中消失了!这段代码有什么问题?
编辑: 感谢您的帮助。 以下是完整更新后的jQuery:
<script>
$(document).ready(function(){
$(".button").click(function() {
var status = $("#status").val();
var course = $("#course").html()
//NEW SECTION that I'm having trouble with
if ($(".button span").html() == "followed") {
$(".button").on("mouseover", function () {
$(".button span").html() = "unfollow";
}}
$.ajax({
type: "POST",
url: "/follow",
data: 'status=' + status + "&course=" + course,
success: function() {
$(".button span").html($(".button span").html() == 'followed' ? 'follow' : 'followed');
$(".button").val($(".button").val() == 'True' ? 'False' : 'True');
}
});
return false;
});
});
</script>
onclick事件已经可以执行。我后来添加了新的onmouseover代码以将“followed”更改为“unfollowed”,并且当我运行它时,会出现
405 Method Not Allowed
The method POST is not allowed for this resource.
这个onmouseover代码有什么问题?
此外,
的功能是什么?return false;
?