将onclick事件分配给Cell

编程入门 行业动态 更新时间:2024-10-23 17:23:39
本文介绍了将onclick事件分配给Cell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我在给单元格分配onclick事件时遇到了麻烦。我正在尝试 类似 cursorPoint.cells [3] .style.cursor =" hand"; cursorPoint。 cells [3] .width =" 20"; cursorPoint.cells [3] .onclick =" alert(''this is a test'');" cursorPoint.cells [3] .alt ="选择列" ;; cursorPoint.cells [3] .innerHTML ="& nbsp;" 除了onclick之外,一切正常。我也试过了: cursorPoint.cells [3] .click =" alert(''这是测试'');" (没有 " on&),但也没有用。 任何帮助都会非常感激 提前致谢 Joao

Hello everyone, I''m having troubles assigning an onclick event to a cell. Im trying something like cursorPoint.cells[3].style.cursor = "hand"; cursorPoint.cells[3].width = "20"; cursorPoint.cells[3].onclick = "alert(''this is a test'');" cursorPoint.cells[3].alt = "Select the columns"; cursorPoint.cells[3].innerHTML = " " Everything is just working fine except the onclick. I also tried: cursorPoint.cells[3].click = "alert(''this is a test'');" (without the "on") but also didnt work. Any help would be much appreciated Thanks in advance Joao

推荐答案

5月9日上午9:52 ,joaotsetsemo ... @ gmail写道: On May 9, 9:52 am, joaotsetsemo...@gmail wrote: 大家好, 我遇到麻烦分配一个onclick事件到一个单元格。我正在尝试 类似 cursorPoint.cells [3] .style.cursor =" hand"; cursorPoint。 cells [3] .width =" 20"; cursorPoint.cells [3] .onclick =" alert(''this is a test'');" cursorPoint.cells [3] .alt ="选择列" ;; cursorPoint.cells [3] .innerHTML ="& nbsp;" 除了onclick之外,一切正常。我也试过了: cursorPoint.cells [3] .click =" alert(''这是测试'');" (没有 " on&),但也没有用。 任何帮助都会非常感激 提前致谢 Joao Hello everyone, I''m having troubles assigning an onclick event to a cell. Im trying something like cursorPoint.cells[3].style.cursor = "hand"; cursorPoint.cells[3].width = "20"; cursorPoint.cells[3].onclick = "alert(''this is a test'');" cursorPoint.cells[3].alt = "Select the columns"; cursorPoint.cells[3].innerHTML = " " Everything is just working fine except the onclick. I also tried: cursorPoint.cells[3].click = "alert(''this is a test'');" (without the "on") but also didnt work. Any help would be much appreciated Thanks in advance Joao

试试这个: addEvent: function(obj,evtype,func){ try { if(window.attachEvent){ obj.attachEvent(" on" + evtype,func); } if(window.addEventListener){ obj.addEventListener(evtype,func,false); } } catch(e){ //如果你想要警告错误 } } obj将是单元格,evtype将是click并且func将是事件发生时您想要调用的任何函数。你还需要保持 ,因为该函数将具有参数的事件,但是从 事件中你可以找到事件的来源。如果这个 不适合你,请告诉我。

Try this: addEvent:function(obj, evtype, func){ try{ if(window.attachEvent){ obj.attachEvent("on"+evtype, func); } if(window.addEventListener){ obj.addEventListener(evtype, func,false); } }catch(e){ //alert the error if you want } } obj will be the cell, evtype will be click and func will be whatever function you want called when the event occurs. You also need to keep in mind that the function will have the event for a parameter but from the event you can find the source of the event. Let me know if this does not work for you.

5月9日下午3:39,Joe<先生; mrjoefri ... @ gmailwrote: On May 9, 3:39 pm, Mister Joe <mrjoefri...@gmailwrote: 5月9日上午9:52,joaotsetsemo ... @ gmail写道: On May 9, 9:52 am, joaotsetsemo...@gmail wrote: 大家好, Hello everyone,

我遇到麻烦分配一个onclick事件到一个单元格。我正在尝试 类似于 I''m having troubles assigning an onclick event to a cell. Im trying something like

cursorPoint.cells [3] .style.cursor =" hand" ;; cursorPoint.cells [3] .width =" 20"; cursorPoint.cells [3] .onclick =" alert(''这是测试'') ;" cursorPoint.cells [3] .alt ="选择列; cursorPoint.cells [3] .innerHTML ="& nbsp; " cursorPoint.cells[3].style.cursor = "hand"; cursorPoint.cells[3].width = "20"; cursorPoint.cells[3].onclick = "alert(''this is a test'');" cursorPoint.cells[3].alt = "Select the columns"; cursorPoint.cells[3].innerHTML = "&nbsp;"

除了onclick之外,一切正常。我也尝试过: Everything is just working fine except the onclick. I also tried:

cursorPoint.cells [3] .click =" alert(''this is a test'');" (没有 " on&);但也没有奏效。 cursorPoint.cells[3].click = "alert(''this is a test'');" (without the "on") but also didnt work.

任何帮助都会非常感激 Any help would be much appreciated

在此先感谢 Thanks in advance

Joao Joao

试试这个: addEvent:function(obj,evtype,func){ try { if(window.attachEvent){ obj.attachEvent(" ; on" + evtype,func); } if(window.addEventListener){ obj.addEventListener(evtype,func,false ); } } catch(e){ //如果你想要警告错误 } } obj将是单元格,evtype将是click并且func将是任何 $事件发生时想要调用的b $ b函数。你还需要保持 ,因为该函数将具有参数的事件,但是从 事件中你可以找到事件的来源。如果这个 不适合你,请告诉我.-隐藏引用的文字 - - 显示引用的文字 -

Try this: addEvent:function(obj, evtype, func){ try{ if(window.attachEvent){ obj.attachEvent("on"+evtype, func); } if(window.addEventListener){ obj.addEventListener(evtype, func,false); } }catch(e){ //alert the error if you want } } obj will be the cell, evtype will be click and func will be whatever function you want called when the event occurs. You also need to keep in mind that the function will have the event for a parameter but from the event you can find the source of the event. Let me know if this does not work for you.- Hide quoted text - - Show quoted text -

你好乔, 感谢您的回复。 我在哪里放这段代码?我是否必须在代码中的某处调用 函数?我需要在代码中更改什么? 顺便说一下,我将有足够的单元来协助onClick事件而不仅仅是一个。

Hi Joe, thanks for your reply. Where do i have to put that piece of code? Do I have to call that function somewhere in my code? What do I have to change in my code? Btw, I will have plenty of cells to assing onClick events and not only one.

jo ****** *******@gmail écrit: jo*************@gmail a écrit : 大家好, 我在向一个小区分配onclick事件时遇到了麻烦。我正在尝试 类似 cursorPoint.cells [3] .style.cursor =" hand"; cursorPoint。 cells [3] .width =" 20" ;; Hello everyone, I''m having troubles assigning an onclick event to a cell. Im trying something like cursorPoint.cells[3].style.cursor = "hand"; cursorPoint.cells[3].width = "20";

cursorPoint.cells [3] .onclick =" alert(''this is a test'');" cursorPoint.cells[3].onclick = "alert(''this is a test'');"

cursorPoint.cells [3] .onclick = function(){alert(''这是测试''); };

cursorPoint.cells[3].onclick = function() { alert(''this is a test''); };

cursorPoint.cells [3] .alt ="选择列" ;; cursorPoint.cells [3] .innerHTML ="& nbsp;" 一切正常,除了onclick。我也尝试过: cursorPoint.cells[3].alt = "Select the columns"; cursorPoint.cells[3].innerHTML = "&nbsp;" Everything is just working fine except the onclick. I also tried:

注意''cursorPoint''实际上是你试图达到的目标 a TD的ID cursorPoint = document.getElementById(''cursorPointTd''); - Stephane Moriaux et son(moins)vieuxMacdéjà dépassé

take care that ''cursorPoint'' is really what you try to reach a TD with an ID cursorPoint = document.getElementById(''cursorPointTd''); -- Stephane Moriaux et son (moins) vieux Mac déjà dépassé

更多推荐

将onclick事件分配给Cell

本文发布于:2023-11-10 00:46:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573907.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   onclick   Cell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!