JS菜鸟求助,用JS画的一个table 给td添加 一个onclick()事件如何传值?
function f1(PARENT_ID) {
$.ajax({
type: "POST",
url: "goods/test.do",//请求的后台地址
data: "PARENT_ID="+PARENT_ID,//前台传给后台的参数
success: function(jsonStr){//jsonStr:返回值
//alert( jsonStr );
//document.getElementById("GOODS_NAME").value=jsonStr;
var json = eval(jsonStr); //数组
var ruleListTemp = "<table class='table table-striped table-bordered table-hover'>";
$.each(json, function (index, item) {
//循环获取数据
var name = json[index].NAME;
var zd_id = json[index].ZD_ID;
ruleListTemp += ("<tr>");
ruleListTemp += ("<td onclick='test2();'>"+name+"</td>");
ruleListTemp += ("</tr>");
});
ruleListTemp += ("</table>");
$("#zhongxin3").html($("#zhongxin3").html()+ruleListTemp);
$("#zhongxin3").show();
}
});
}
function test2(a) {
alert("aaaaaaaaaa"+a);
//document.getElementById("GOODS_NAME").value=a;
document.getElementById("zhongxin3").style.display="none";//隐藏
}问题主要是
ruleListTemp += ("<td onclick='test2();'>"+name+"</td>");
onclick='test2();' 或者onclick='test2(1111);' 这种都是OK 没有问题 td是可以点击的 test2();中的alert 也是可以弹出的
但是
ruleListTemp += ("<td onclick='test2("+name+");'>"+name+"</td>");
或是
ruleListTemp += ("<td onclick='test2('"+name+"');'>"+name+"</td>");
都是不行的
求大神 尽量 讲详细点 为什么 这个值 不能 带到 test2();中 应该怎样写

...全文
相关推荐
用jQuery自己写的一个表格——jQuery菜鸟入门,希望和大家一起学习
NULL 博文链接:https://630636339.iteye.com/blog/1694435
JavaScript实现九九乘法表的简单实例
每个学过编程的人都写过“HelloWorld” 但99乘法表,我想也应该成为每个编程初学者的必编程序 这是JavaScript的实现方法,非常适合初学者!!! 以下是代码及注释 <!DOCTYPE html> <head> <meta http-equiv=Content-Type content=text/html; charset=gb2312 /> <title>JavaScript九九乘法表</title> <style type=text/css> table{ width:600px; //表格height属性可设置可不设置,建议不设置 border
n8n@2.48.5离线安装包
windows n8n@2.48.5离线安装包
Docker Desktop Installer.exe
Docker Desktop Installer.exe
Python Vibe Coding:本地文档智能审查与摘要 实验源码与结果压缩包
Python Vibe Coding:本地文档智能审查与摘要 实验源码与结果压缩包


