简体   繁体   English

我可以在 javascript function 中重用 function 中使用的变量吗?

[英]Can I reuse variables used in function in javascript function?

string empCode = ds.Tables[0].Rows[i]["EMP_CODE"].ToString();
        string empName = ds.Tables[0].Rows[i]["EMP_NAME"].ToString();
        string gradeCode = ds.Tables[0].Rows[i]["GRADE_CODE"].ToString();

        tr = new TableRow();

        td = new TableCell();
        td.Attributes.Add("onClick", "javascript: " +
            "if(confirm(empName)==true){self.close();}" +  //this Line
            "else{return;}");

I want to reuse empName in the commented part.我想在评论部分重用 empName 。 Is there a way to reuse it?有没有办法重用它?

Please try as show below,请尝试如下所示,

td.Attributes.Add("onClick", "javascript: " +
        "if(confirm(" + empName + ") === true){self.close();}" +  //this Line
        "else{return;}");

or try或尝试

td.Attributes.Add("onClick", "javascript: " +
        "var empName=" + empName + "; if(confirm(empName) === true){self.close();}" +  //this Line
        "else{return;}");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM