Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将jQuery函数应用于表行,但不应用于第一个表数据_Javascript_Jquery_Html - Fatal编程技术网

Javascript 将jQuery函数应用于表行,但不应用于第一个表数据

Javascript 将jQuery函数应用于表行,但不应用于第一个表数据,javascript,jquery,html,Javascript,Jquery,Html,我有一张多行的桌子。单击每一行将用户重定向到一个唯一的url。 我的问题是如何在表行上应用click事件,但是td with action类不应该受clickable行的影响? 我尝试了:notjQuery选择器,但不幸的是,我对jQuery非常陌生。谢谢 这是我的桌子: <table id="tblHotel"> <thead> <tr> <th class="sorting_disabled">&nbsp;<

我有一张多行的桌子。单击每一行将用户重定向到一个唯一的url。 我的问题是如何在表行上应用click事件,但是td with action类不应该受clickable行的影响? 我尝试了:notjQuery选择器,但不幸的是,我对jQuery非常陌生。谢谢

这是我的桌子:

<table id="tblHotel">
<thead>
    <tr>
        <th class="sorting_disabled">&nbsp;</th>
        <th>ID</th>
    </tr>
</thead>
<tbody>
    <tr id="1" >
        <td class="actions">
            <a href="hotel/update/1"><i class="icon-pencil"></i> Edit</a>
            <a href="#"><i class="icon-trash"></i> Delete</a>
        </td>
        <td>1</td>
    </tr>
</tbody>

身份证件
1.

以下是jQuery ajax:

$("#tblHotel tbody tr").click(function(){

var hotelid = $(this).attr('id');
$.ajax({
    type: "POST",                   
    url: "<?=site_url('hotel/view')?>/" + hotelid,
    success: function(data){
        $('.hiddenSidebar').html(data).show('slide', { direction: 'right' }, 300);
    },
    error: function(){
        alert('error!');
    }                       
});
}).not('tr td.actions');
$(“#TBL酒店tbody tr”)。单击(功能(){
var hotelid=$(this.attr('id');
$.ajax({
类型:“POST”,
url:“/”+hotelid,
成功:功能(数据){
$('.hiddenSidebar').html(data.show('slide',{direction:'right'},300);
},
错误:函数(){
警报('错误!');
}                       
});
}).不是(“tr td.行动”);
试试看


您可以检查单击的内容,请尝试以下操作:

$("#tblHotel tbody tr").click(function(e){
    if($(e.target).is('.actions')) return false;
    var hotelid = $(this).attr('id');
    $.ajax({
        type: "POST",                   
        url: "<?=site_url('hotel/view')?>/" + hotelid,
        success: function(data){
            $('.hiddenSidebar').html(data).show('slide', { direction: 'right' }, 300);
        },
        error: function(){
            alert('error!');
        }                       
    });
});
$(“#TBL酒店tbody tr”)。单击(功能(e){
if($(e.target).is('.actions')返回false;
var hotelid=$(this.attr('id');
$.ajax({
类型:“POST”,
url:“/”+hotelid,
成功:功能(数据){
$('.hiddenSidebar').html(data.show('slide',{direction:'right'},300);
},
错误:函数(){
警报('错误!');
}                       
});
});
$(“#tblHotel tbody tr”)。不('td.actions')。单击(函数(){
var hotelid=$(this.attr('id');
$.ajax({
类型:“POST”,
url:“/”+hotelid,
成功:功能(数据){
$('.hiddenSidebar').html(数据).show('slide'){
方向:“对”
}, 300);
},
错误:函数(){
警报('错误!');
}
});
});

如果您使用的是jQuery UI,则图标类应该如下所示:

<table id="tblHotel">
    <thead>
        <tr>
            <th class="sorting_disabled">&nbsp;</th>
            <th>ID</th>
        </tr>
    </thead>
    <tbody>
        <tr id="1">
            <td class="actions"> <a href="hotel/update/1"><i class="ui-icon ui-icon-pencil" title="Edit"></i></a>
 <a href="#"><i class="ui-icon ui-icon-trash" title="Delete"></i></a>
            </td>
            <td>1</td>
        </tr>
    </tbody>

身份证件
1.

每个tr的id值是多少?这有多行具有唯一id。您需要
返回false
或使用
e.stopPropagation()
,否则事件将冒泡到
TR
,并且
.is()
检查将失败。问题是当我单击编辑链接时,警报('error!')不断出现。问题似乎出现在ajax函数中,对吗@markyorky@AlessandroMinoccheri,不是真的。。场景是,单击每一行将重定向到不同的url。每一行都循环使用唯一的id。
$("#tblHotel tbody tr").click(function(e){
    if($(e.target).is('.actions')) return false;
    var hotelid = $(this).attr('id');
    $.ajax({
        type: "POST",                   
        url: "<?=site_url('hotel/view')?>/" + hotelid,
        success: function(data){
            $('.hiddenSidebar').html(data).show('slide', { direction: 'right' }, 300);
        },
        error: function(){
            alert('error!');
        }                       
    });
});
$("#tblHotel tbody tr").not('td.actions').click(function () {
    var hotelid = $(this).attr('id');
    $.ajax({
        type: "POST",
        url: "<?=site_url('hotel/view')?>/" + hotelid,
        success: function (data) {
            $('.hiddenSidebar').html(data).show('slide', {
                direction: 'right'
            }, 300);
        },
        error: function () {
            alert('error!');
        }
    });
});
<table id="tblHotel">
    <thead>
        <tr>
            <th class="sorting_disabled">&nbsp;</th>
            <th>ID</th>
        </tr>
    </thead>
    <tbody>
        <tr id="1">
            <td class="actions"> <a href="hotel/update/1"><i class="ui-icon ui-icon-pencil" title="Edit"></i></a>
 <a href="#"><i class="ui-icon ui-icon-trash" title="Delete"></i></a>
            </td>
            <td>1</td>
        </tr>
    </tbody>