Php 显示更多按钮,带变量的div id

Php 显示更多按钮,带变量的div id,php,javascript,ajax,html,Php,Javascript,Ajax,Html,我正在制作一个小脚本,在显示10个条目的最后显示更多按钮。 这是密码 <div id="more<?=$lastid;?>"> <a onclick="showmore(<?=$lastid;?>);">More</a> </div> 但是脚本不起作用?这里有什么问题 我用一个常量div id测试了脚本,它运行得很好,但是当我在脚本端为div添加$lastid和$(“#more”+lastid)时,它不起作用 有

我正在制作一个小脚本,在显示10个条目的最后显示更多按钮。 这是密码

<div id="more<?=$lastid;?>">
   <a onclick="showmore(<?=$lastid;?>);">More</a>
</div>  
但是脚本不起作用?这里有什么问题

我用一个常量div id测试了脚本,它运行得很好,但是当我在脚本端为div添加$lastid和$(“#more”+lastid)时,它不起作用

有什么办法可以更改DIV ID吗


提前感谢

与其将id附加到更难看的more,不如给div一个类“more”


在setTimeout()的字符串中引用lastid。您应该使用闭包来解决这个问题。然而,这里有一个干净的版本:

function showmore(lastid) {
    $.post("/ajax/showmore.php",
        { lastid:lastid },
        resultHandler);

    return false;

    function resultHandler(response) {
        $("#more" + lastid).html(response).fadeIn(1e3);
    }
}
谢谢大家

我发现了错误

就在这一行

            setTimeout("finishAjax('more' + lastid, '"+escape(response)+"')", 300);
我把它改成

            setTimeout("finishAjax('more"+lastid+"', '"+escape(response)+"')", 300);

感谢您的回答

如果$lastid是一个字符串而不是一个数字,您需要将其用引号括起来,否则javascript将中断:它是一个数字!!但我想我会试试你的主意
function showmore(lastid) {
    $.post("/ajax/showmore.php",
        { lastid:lastid },
        resultHandler);

    return false;

    function resultHandler(response) {
        $("#more" + lastid).html(response).fadeIn(1e3);
    }
}
            setTimeout("finishAjax('more' + lastid, '"+escape(response)+"')", 300);
            setTimeout("finishAjax('more"+lastid+"', '"+escape(response)+"')", 300);