JQuery:缺失;之前的声明

JQuery: missing ; before statement

本文关键字:声明 缺失 JQuery      更新时间:2023-09-26

我不知道为什么我得到这个错误(我阅读了每个主题与类似的名称,但这些问题的答案不适用):

$(document).ready(function() {
postAndFade($node, post_key) {
    var id = $node.parents.('.id').find('.id-value').text();
    var post_val = $node.text();
    $node.fadeOut('slow');
    $.ajax({
        type: "POST",
        url: "process.php",
        data: "id="+id+"&"+post_key+"="+post_val,
        success: function(data) {
            $node.html(data);
            $node.fadeIn('slow');           
        }
    });
    return false;
}
$('.featured-value').click(function() { return postAndFade($this, 'featured'); });
$('.visible-value').click(function() { return postAndFade($this, 'visible'); });
});
postAndFade($node, post_key) {

你漏掉了function关键字。

var id = $node.parents.('.id').find('.id-value').text();

parents之后有一个额外的.

这里没有使用关键字function声明函数。

postAndFade($node, post_key)

应该是这样的:

function postAndFade($node, post_key) {

在定义函数postAndFade之前,您缺少关键字function