在已生成的静态页加鼠标事件问题
我有一个TABLE是控件生成的,现在在TABLE中不方便加事件了,有没有办法,通过JQUERY加事件?
Table脚本如下:
<table id="uicTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr id="row">
<td align="" class="chboxtd"><div style="width: 22px;"><input class="itemchk" id="chk_" type="checkbox" value=""></div></td>
<td align="left"><div style="width: 90px; text-align: left;"><span><code class="codeSpan">13953654</code></span></div></td>
<td align="left"><div style="width: 90px; text-align: left;"><span><code class="codeSpan">35416005</code></span></div></td>
<td align="left"><div style="width: 384px; text-align: left;"><span><code class="codeSpan">Apache-HttpClient</code></span></div></td>
<td align="left" class=" tdLast"><div style="width: 546px; text-align: left;"><span><code class="codeSpan">http://m.baidu.com/appsrv?action=clientlog&</code></span></div></td>
</tr>
<tr class="erow" id="row">
<td align="" class="chboxtd"><div style="width: 22px;"><input class="itemchk" id="chk_" type="checkbox" value=""></div></td>
<td align="left"><div style="width: 90px; text-align: left;"><span><code class="codeSpan">13955200</code></span></div></td>
<td align="left"><div style="width: 90px; text-align: left;"><span><code class="codeSpan">35211305</code></span></div></td>
<td align="left"><div style="width: 384px; text-align: left;"><span><code class="codeSpan">Apache-HttpClient/UNAVAILABLE (java 1.4)</code></span></div></td>
<td align="left" class=" tdLast"><div style="width: 546px; text-align: left;"><span><code class="codeSpan">http://r6.mo.baidu.com/v4/?c=noti&sp=0&pm3=406358&ptime=-1&env=2&</code></span></div></td>
</tr>
<tr id="row"><td align="" class="chboxtd"><div style="width: 22px;"><input class="itemchk" id="chk_" type="checkbox" value=""></div></td>
<td align="left"><div style="width: 90px; text-align: left;"><span><code class="codeSpan">13955540</code></span></div></td>
<td align="left"><div style="width: 90px; text-align: left;"><span><code class="codeSpan">35687104</code></span></div></td>
<td align="left"><div style="width: 384px; text-align: left;"><span><code class="codeSpan">UNAVAILABLE (java 1.4)</code></span></div></td>
<td align="left" class=" tdLast"><div style="width: 546px; text-align: left;"><span><code class="codeSpan">http://andmbd.tj.ijinshan.com/data/?androidid=85043813364486de&andver=4.0.3&</code></span></div></td></tr>
<tr class="erow" id="row">
<td align="" class="chboxtd"><div style="width: 22px;"><input class="itemchk" id="chk_" type="checkbox" value=""></div></td>
<td align="left"><div style="width: 90px; text-align: left;"><span><code class="codeSpan">13955705</code></span></div></td>
<td align="left"><div style="width: 90px; text-align: left;"><span><code class="codeSpan">35156805</code></span></div></td>
<td align="left"><div style="width: 384px; text-align: left;"><span><code class="codeSpan">~___311(android)</code></span></div></td>
<td align="left" class=" tdLast"><div style="width: 546px; text-align: left;"><span><code class="codeSpan">http://r.inews.qq.com/getQQNewsIndexAndItems?qqnetwork=gsm&store=68&hw=samsung_GT-S7508&devid=351568052087195&</code></span></div></td>
</tr>
</tbody>
</table>
不改变TABLE结构的情况下,如何在最后一个TD列中,添加事件呢?
我这么处理的:
1、动态创建一个DIV;
var newa = document.createElement("a");
newa.setAttribute("id", "share");
newa.setAttribute("href", "#");
newa.setAttribute("style", "display:none;");
var bodyTags = document.getElementsByTagName("body");
var thisBody = bodyTags[0];
thisBody.appendChild(newa);
$("#share").css({
width: '32px',
height: '32px',
position: 'absolute',
background: 'url(/images/dialog/sina.png) no-repeat',
'text-decoration': 'none',
display: 'none'
});
var content = document.getElementsByTagName("div");
var sina;
for (var i = 0; i < content.length; i++)
select(content[i], function (txt, tar, mouseP) {
sina = document.getElementById("weiboshare");
AllSee = mouseP;
sina.style.left = document.body.scrollLeft + mouseP.x + 5 + "px";
sina.style.top = document.body.scrollTop + mouseP.y - 30 + "px";
sina.style.display = "block";
share(sina, { title: txt });
//window.alert(sina);
}, function () {
;
});
结果每个TD列都可以点击这个事件,现在不知道怎么控制住只让最后一个TD列有事件了。麻烦帮忙看看吧! 感谢。