jquery是这么写。这是排除了第一列onclick。
$("TR td:gt(0)").click
我要排除首尾两列的td触发事件。
请问用原生态js怎么写。谢谢各位。
解决方案 »
- jsp页面的IP参数传递给调用的ocx控件问题,
- 关于jq 或者JS手动创建节点并赋属性值
- JS中怎么把页面的值传到iframe中的页面中去
- 问个fck的简单问题
- 如何增加下拉式导航菜单
- 【求助】我用js封装的json文本怎么才能通过EL表达式将里面的值放到页面的表格中?
- 怎样获取表单元素的名字?急
- 请问javascript中如何判断限制某个输入筐的字数不能超过一个数。
- 问一个关于JSCRIPT的菜问题。。。
- javascript请指点 这个代码看不懂。
- jqgrid grid中的rowid与数据有关系吗?我在用updateGridRows时弄糊涂了
- jQuery如何在父窗口中操作iframe中的元素?
<tr>
<td>1111111</td>
<td>1111111</td>
<td>1111111</td>
<td>1111111</td>
<td>1111111</td>
<td>1111111</td>
</tr>
</table>
</body>
<script type="text/javascript">
var td = document.getElementById("tb").getElementsByTagName("tr")[0].getElementsByTagName("td")
for(var i = 0 ; i < td.length ; i ++)
{
td[i].onclick = function(){alert("x")}
}
for(var i = 0 ; i < td.length ; i ++)
{
if(i == 0 || i ==td.length - 1) td[i].onclick = null
}
</script>
SItem[i].Sbtr.onmouseover = function ()
{
this.className = (this.className != '') ? this.className + ' onmouseover' : 'onmouseover';
}
SItem[i].Sbtr.onmouseout = function ()
{
this.className = this.className.replace(/onmouseover/, '');
}SItem[i].Sbtr.onmousedown = function (event)
{ // 按住Shift键
event = event? event:window.event;
if((!document.all && event.button == 1) ||event.button == 4) return; if(event.shiftKey==true && StartTr != null)
{
EndTr = this.key;
var StartGo = StartTr; // 开始的Tr KEY
var Sum = StartTr - EndTr; // 个数
if(Sum > 0) var StartGo = EndTr;
Sum = Math.abs(Sum);
if(Sum < 1) return;
var EndGo = Sum + StartGo +1;
for (; StartGo < EndGo; ++StartGo)
{
ClickTr(SItem[StartGo].Sbtr, false);
}
SEstatus = false;
return;
}
else
{
StartTr = this.key;
SEstatus = true;
if(event.button == 2) // 右键选择
ClickTr(this, false); // 只能选上
else
ClickTr(this, true); // 自由切换
}
}
//循环绑定的时候 处理下首尾 不就行了 。
}
td.removeEventListener(“click”, handler, false);
for(var i=0; i<td.length; i++) {
if(i!=0 && i!=td.length-1) {//排除首尾
td[i].onclick = function() {
//......
}
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body><table border="1">
<tr onclick="fn()">
<td id="t1">取消了事件</td>
<td >点我,我没取消</td>
<td id="t2">取消了事件</td>
</tr>
</table>
<script type="text/javascript"> function stopBubble(e) {
if (e && e.stopPropagation) {
e.stopPropagation();
}
else {
window.event.cancelBubble = true;
}
}
document.getElementById('t1').onclick = function (e) {
stopBubble(e);
}
document.getElementById('t2').onclick = function (e) {
stopBubble(e);
}
function fn() {
alert('s');
} </script>
</body>
</html>