简体   繁体   English

单击回调事件生成的表内的链接按钮时,如何在javascript中调用函数

[英]How to call a function inside javascript when clicking a link button inside a table generated by callback event

       function ReceiveServerData(retValue) {          
        var val = retValue.split('#')
        var ch1= val[1].split(',');
        if (val[0] == 1) {
            var tab = "";
           //codes
            var row = ch1.split("¥");
                for (n = 0; n <= row.length - 1; n++) {
                    var col = row[n].split("µ");
                    tab += "<td style='width:5%;text-align:left'><a href onclick ='Documents(" + col[0] + "," + i + ")'  style='text-align:left;'>Download Attachment </td>";
             //codes

        }
    }         
    function Documents(ID,i) {
        //codes
    }

it doesn't seem to work correctly though. 它似乎无法正常工作。 Is there a better way to do this? 有一个更好的方法吗?

change this: 改变这个:

tab += "<td style='width:5%;text-align:left'><a href onclick ='Documents(" + col[0] + "," + i + ")'  style='text-align:left;'>Download Attachment </td>";

to this: 对此:

tab += "<td style='width:5%;text-align:left'><a href='#' onclick='Documents(" + col[0] + "," + i + ")'  style='text-align:left;'>Download Attachment </td>";

tips: 1. You should give a "#" to href else it will go refresh your page. 提示:1.您应该给href加上“#”,否则它将刷新您的页面。

  1. You should connect the string between "onclick" and "=" to make html template reasonable. 您应该在“ onclick”和“ =”之间连接字符串,以使html模板合理。

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

相关问题 如何在某个事件(例如单击链接)中从Jquery内部调用Javascript函数? - How to call a Javascript function from inside a Jquery on some event like clicking of a link? 单击html表中的按钮时如何调用javascript函数? - How to call a javascript function when a button inside html table is clicked? 如何在JavaScript的回调中调用Typescript函数 - How to call a typescript function inside callback of a JavaScript 使用jQuery单击动态生成的链接时如何调用函数? - How to call a function when clicking a dynamically generated link, using jQuery? Javascript 按钮 onclick 事件调用 function 内部 ZC1C425268E68385D14AB5074C17A 模块 - Javascript button onclick event to call function inside function in module 如何访问 JavaScript 事件回调函数内的变量? - How to access variables that are inside a callback function of a JavaScript event? 如何在回调函数中调用继承的函数 - How to call a inherited function inside a callback function 如何在事件中调用 function? - How to call a function inside a event? 在内部<a>链接</a>上单击时禁用div上的onclick事件<a>(无js框架)</a> - disable onclick event on div when clicking on inside <a> link (No js framework) 单击行内的按钮时,防止触发表行 onclick 事件 - Prevent table row onclick event to fire when clicking button inside the row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM