~Onlooker 2015-08-17 01:43 采纳率: 0%
浏览 357

AJAX内部if语句

This is my onclick function. The code without the if statement runs perfectly. I'm trying to test if sbmt is equal to 1 and only then remove the row. But once I add the if statement, the row cannot be removed. What is wrong with my code?

function taskOnclick(row,task) {
    var url = 'remove_task.asp?task='+task;

    if (<%=("SBMT")%> === 1){ 
        $(this).row.closest('tr').remove();
        $.ajax({url: url, success: function(result){
            alert(result);
        }});
    }
};
<tr id="taskid">
        <%
            If objRS("REAS") <> "" Then
                strReason = "<br/><br/><b style=""color: red"">Reason: "&objRS("REAS")&"</b>"
            Else
                strReason = ""
            End If
            Response.Write "<td onclick=""taskOnclick(this,'"&objRS("TASK")&"')""><a href=""#"">" & objRS("TASK") & "<span>"&objRS("REMK")& strReason & "</span></a></td>"
            Response.write "<td>" & objRS("DDAT") & "</td>"
            Response.write "<td class=""days"" style=""text-align:center"">" & objRS("DAYS") & "</td>"
            Response.write "<td >" & objRS("CDAT") & "</td>"


        %>
</tr>

UPDATED

function taskOnclick(row,task) {
    var url = 'remove_task.asp?task='+task;
    var SBMT = <%=objRS("SBMT")%>;

if (SBMT == '1'){ 
    row.closest('tr').remove();

$.ajax({url: url, success: function(result){
    alert(result);
}});
}
else if (SBMT == '0'){
    alert("NO");
}
};

SQL

strWhere = " where acti= '1' "
    strSQL = "select task,ddat,ddat-trunc(sysdate) as days,prog,pnam,remk,reas,nvl(to_char(cdat,'dd/mm/yyyy'),'INPG') as cdat,sbmt from task" & strWhere
    strSQL = strSQL & "order by prog,ddat"
  • 写回答

1条回答 默认 最新

  • weixin_33697898 2015-08-17 08:49
    关注

    This line:

    if (<%=("SBMT")%> === 1){ 
    

    is going to be written to your document as the following JavaScript:

    if (SBMT === 1){ 
    

    JavaScript is going to assume that SBMT is a JavaScript variable and test it to see if its value is strictly equal to 1. I don't see a JavaScript variable with this name defined in your code, so this is going to cause the following error when your JavaScript runs:

    Uncaught ReferenceError: SBMT is not defined

    and, therefore, the contents of your if block will never be executed.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝