0

私はjsスクリプトにこの関数を持っています。

//handle the deleting of the shoutlines
function delete_shoutline(shoutline_number)
{
    //the number of the shoutline we're deleting
    var shoutline = shoutline_number;

    $.post("shoutbox/delete_ban.php", {shoutline : shoutline_number},
    function(result)
    {
        //show the result, if any
        alert(result);

        //refresh the page
        window.location = window.location;
    });

}
//handle the banning of users
function ban_user(user_ban)
{
    //the name of the user we are banning
    var banned = user_ban;

    $.post("shoutbox/delete_ban.php", {banned : user_ban},
    function(result)
    {
        //show the result, if any
        alert(result);

        //refresh the page
        window.location = window.location;
    });

}

ここに呼び出しがあります

<a href='javascript: delete_shoutline(SOMEID);' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='javascript: ban_user(SOMEUSER);' title='Ban' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>

この機能delete_shoutlineはうまく機能しますが、禁止リンクをクリックすると、コンソールが一時停止して次のように表示されます(anonymous function) members.php (2):1 Paused on exception 'ReferenceError'

そしてデバッガーは言うUncaught ReferenceError: SOMEUSER is not defined

私はjsが得意ではないので、これが何を意味するのか本当にわかりませんか? 関数はjsで定義されているため、これが何を意味するのかよくわかりません。

4

2 に答える 2

1

文字列を引用符で囲む必要があります。

<a href='javascript: ban_user(SOMEUSER);'  <-- no quotes around SOMEUSER, it thinks it is a variable. 
于 2012-12-10T21:51:23.663 に答える
0

SOMEUSER はユーザー名であるべきですか? もしそうなら、それを引用してください。たとえば、ban_user("SOMEUSER") SOMEID は int である可能性が高いため、いくつかのシャウトラインを削除する際に引用する必要はありません。したがって、引用する必要はありません。ただし、文字列は引用符で囲む必要があります。そうしないと、変数であると見なされます。

于 2012-12-10T21:56:26.157 に答える