代码生成一个span标签,但是当点击该标签时要调用某个函数,需要传参数,这参数该怎么传?

//添加行
function addRow(customer, cusAddr) {
var tblObj = document.getElementById("tblDiv");
var newRow = tblObj.insertRow(tblObj.rows.length - 2);
var newColCustomer = newRow.insertCell(newRow.cells.length);
var newSelect = newRow.insertCell(newRow.cells.length);
newColCustomer.innerHTML = customer;
newSelect.innerHTML = "<span style='cursor:hand;' onclick='showAddress(customer)'">[选择]</span>"
alert(newSelect.innerHTML);
}
function showAddress(customer) {
alert(customer);--结果是[object Object]
document.getElementById("customerName").value = customer;//结果object
//document.getElementById("address").value = cusAddr;
alert("----------------------------------");
}

PIPIONE
浏览 181回答 3
3回答

慕的地6264312

<script>function mover(obj){obj.style.backgroundColor="#00ccff";obj.style.borderWidth="2px";obj.style.borderStyle="dashed";}function mout(obj){obj.style.backgroundColor="White";obj.style.borderWidth="1px";obj.style.borderStyle="solid";}</script><span style="border-style:solid;border-width:1px;" onmouseover="mover(this)" onmouseout="mout(this)">This is a span</span>

红颜莎娜

newSelect.innerHTML = "<span style='cursor:hand;' onclick='showAddress(“+customer+”)'">这句这样改一下

慕婉清6462132

newSelect.innerHTML = "<span style='cursor:hand;' onclick='showAddress(\"" + customer+"\");'">[选择]</span>"
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript