success: function (data) {
if(data=='alreadysubmit')
{
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function()
{
alert("hi");
});
}
else{
$("input:checked").next().text('Votes:'+data);
}
}
以上是我的代码片段,它应该在javascrpit draw.js中加载Google Visualization APT。 draw.js是我本地驱动器中的其他位置,我想我可以在$ .getScript函数中触发它,因为在draw.js中有一些我需要用于当前页面的函数。顺便说一句,警报(“hi”)确实生效了,页面继续加载......我应该这样做吗?我的想法是,只有满足条件才能使用draw.js,if(data =='alreadysubmit')。先感谢您。
答案 0 :(得分:1)
success: function (data) {
if(data=='alreadysubmit'){
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function()
{
alert("hi");
});
}else{
$("input:checked").next().text('Votes:'+data);
}
}
此?
答案 1 :(得分:0)
条件块内的多行必须由{
和}
包围。
所以:
if (data=='alreadysubmit')
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function() {
alert("hi");
});
变为:
if (data=='alreadysubmit') {
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function() {
alert("hi");
});
}
您的代码段在这方面得到了充分纠正:
if (data == 'alreadysubmit') {
alert("Sorry,but you have already submitted your answer");
$.getScript('static/js/draw.js', function() {
alert("hi");
});
}
else {
$("input:checked").next().text('Votes:'+data);
}