定义函数时,暂停匿名函数

时间:2012-12-10 21:44:59

标签: javascript

我在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中定义的。

2 个答案:

答案 0 :(得分:1)

你需要在字符串周围加引号。

<a href='javascript: ban_user(SOMEUSER);'  <-- no quotes around SOMEUSER, it thinks it is a variable. 

答案 1 :(得分:0)

SOMEUSER应该是用户名吗?如果是这样,请引用它,例如ban_user("SOMEUSER")你不需要引用删除一些shoutline因为SOMEID可能是一个int,所以不需要引用它。但是需要引用字符串,否则它假定它是变量。

相关问题