简体   繁体   English

如何传递元素onclick?

[英]How to pass an element onclick?

Actually i'm trying to pass a td element with which i have to do some operations on a td click or better i have a function where i use the following code实际上,我正在尝试传递一个 td 元素,我必须使用该元素对 td 单击或更好地进行一些操作,我有一个使用以下代码的函数

 var tr = document.getElementById($('#tavolo').val());
  $(`td:eq(${inizio})`, tr).css('background-color', 'red') .attr("onclick","Elimina('" + tr + "');");

when the user will click a td it will open a modal and then in that modal there is a button that call another function which will delete some elements from that td.当用户单击 td 时,它将打开一个模态,然后在该模态中有一个按钮调用另一个函数,该函数将从该 td 中删除一些元素。

The issue is that "[object HTMLTableRowElement]" is passed as tr element so i'm unable to make any operation on it.问题是“[object HTMLTableRowElement]”作为 tr 元素传递,因此我无法对其进行任何操作。

If it's usefull here is the function Elimina如果它有用,这里是功能 Elimina

function Elimina(tr) {
    $('#del').attr("onclick", "eliminaPrenotazione('" + tr + "');");
}

While here is the function eliminaPrenotazione虽然这里是功能 eliminaPrenotazione

function eliminaPrenotazione(tr) {
var start = 1;

        for (i = 0; i <= 8; i++) {
            $(`td:eq(${start})`, tr).css('background-color', 'white').removeAttr("class").find('span').remove();
        }
    }

Here is html code of what td looks like ( i can't post all html as it has 96 similar td's)这是 td 的 html 代码(我无法发布所有 html,因为它有 96 个类似的 td)

<td style="padding: 0px; position: relative; background-color: red;" class="48:15" data-inizio="12:00" data-fine="16:00" onclick="Elimina('48:15','Ihor','12:00','16:00','[object HTMLTableRowElement]');"><span class="tag" style="width: 160px; overflow: hidden;" onmouseover="highlight(this);" onmouseout="unhighlight(this)">Ihor</span></td>

I'm just going to give you an indication to try to put you on the right way.我只是给你一个指示,试图让你走上正确的道路。

You can to do something looks like that :你可以做一些看起来像这样的事情:

$("#yourBtnID").click(function(elem){
   $("#yourDivID").append("<td>" + elem + "</td>");
});

it will add a line td to the each click basically它基本上会在每次点击时添加一行 td

Now you can try to modify your own code and come back if you don't succeed现在可以尝试修改自己的代码,不成功就回来

Good luck ;)祝你好运 ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM