2

我是桌面开发人员,是网络开发的新手。我的函数在函数上方返回错误:

function briefingScreen(gameObjectElement)
{
    $(gameObjectElement).html('<div id="briefing"></div>');
    $("#briefing").append('<div id="start_button"></div>');
    $("#briefing").append('<div id="briefing_text"></div>');
    $.post("php/text.php", "teste",//{screen: "briefingScreen", field:"mainText"},
        function(callback)
        {
            $.("#briefing_text").html(callback);
        }, "html");

        $("#start_button").click(function()
        {
            window.alert("Start Button");
        }
    }

我在谷歌浏览器中调试,错误是Uncaught SyntaxError: Unexpected Token ).

我已经搜索但没有找到解决方案。任何人都可以帮忙吗?

4

2 回答 2

1

从以下位置删除 // 注释:

$.post("php/text.php", "teste",//{screen: "briefingScreen", field:"mainText"},

于 2013-05-05T00:35:52.217 回答
0

您需要正确关闭您的点击功能:

$("#start_button").click(function() {
    window.alert("Start Button");
});

并删除期间

$("#briefing_text").html(callback);

然后你会得到更像:

function briefingScreen(gameObjectElement) {
    var briefing = $('<div />', {id:'briefing'}),
        start    = $('<div />', {id:'start_button'}),
        text     = $('<div />', {id:'briefing_text'});

    briefing.append(start, text);
    $(gameObjectElement).html(briefing);

    $.post("php/text.php", "teste", function(callback) {
        text.html(callback);
    }, "html");

    start.click(function() {
        alert("Start Button");
    });
}
于 2013-05-04T23:42:20.583 回答