javascript 代码生成一个span标签,但是当点击该标签时要调用某个函数,而且需要传参数,这参数该怎么传?
//添加行functionaddRow(customer,cusAddr){vartblObj=document.getElementById("tblDiv");var...
//添加行
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("----------------------------------");
} 展开
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("----------------------------------");
} 展开
3个回答
展开全部
<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>
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+”)'">
这句这样改一下
这句这样改一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
newSelect.innerHTML = "<span style='cursor:hand;' onclick='showAddress(\"" + customer+"\");'">[选择]</span>"
追问
为什么要加\呢?能解释一下吗
我加了\后,就能成功了。
追答
\表示转义,指示后面跟的那个是字符串里的字符
而不是与最前面的双引号配对用的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询