双击未定义或值为0的记录时显示警报

问题描述 投票:0回答:1

你好,下午,我在双击未定义的行之一时显示警报时遇到问题,我试图做的是,当我双击不存在的无限长行时,它将显示以下警报,并且如果该行与未定义的行不同,则显示模态

$("#tableexample tbody").on('dblclick','tr',function(){
        var id = $(this).attr("id");

        if(id === undefined){
        alert("error!");
        }

        if(id !== undefined){
            console.log(id);
            $.ajax({
               url: "example.php?oper=example&id="+id,
               dataType: "json",
               beforeSend: function(){
               },success: function(item) {
                    console.log(item);
                        $("#idexample").val(id);
                        $("#name_edit").val(item.data.name);
                        $("#description_edit").val(item.data.description);
                        $('#modalexeampleedit').modal('show');
               }
            });
        }
    });
javascript jquery alert
1个回答
0
投票

[最近在我的React应用程序中,我正在处理类似的问题:当您双击表行时,您会认为您引用了该表的行,但实际上该行中的列会触发事件(HTMLTableCellElement作为结果),除非您的表行是可聚焦的并且具有tabindex <tr tabindex="0">(请参阅https://stackoverflow.com/a/16959202/8216122)。您可以引用由var r = document.getElementById("TableId").rows[e.parentNode.rowIndex];单击的表行,其中e是双击HTMLTableCellElement返回的引用。根据您的情况,var id = $(this).attr("id");必须为HTMLTableCellElement ID。

© www.soinside.com 2019 - 2024. All rights reserved.