我是桌面开发人员和web dev的新手。我的函数在函数上方返回一个错误:
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");
}
}我在google chrome中调试,错误是Uncaught SyntaxError: Unexpected Token )。
我已经找过了,但没有找到解决方案。有人能帮上忙吗?
发布于 2013-05-05 08:35:52
从以下位置删除//注释:
$.post("php/text.php", "teste",//{screen: "briefingScreen", field:"mainText"},
发布于 2013-05-05 07:42:21
您需要正确关闭您的单击功能:
$("#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");
});
}https://stackoverflow.com/questions/16379962
复制相似问题