如何选中一行(前段js)

html页面:
<div class="mt-20">
    <table class="table table-border table-bordered table-bg table-hover table-sort">
        <thead>
        <tr class="text-c" id="allcheck">
            <th class="bs-checkbox " style="width: 36px; " data-field="state" tabindex="0">
                <div class="th-inner ">点击单选</div><div class="fht-cell"></div></th>
            <!--<th width="60">媒体ID</th>-->
            <th width="60">标题</th>
            <th width="60">文件</th>
        </tr>
        </thead>
        <tbody>
        {volist name="resinfo" id="vo"}
        <tr class="text-c">
            <td class="bs-checkbox "><div class="radio-box"><input data-index="{$vo.aid}" name="btSelectItem" type="radio" value="{$vo.aid}" οnclick="checkedvalue()"></div>
            </td>
            <!--<td width="60">{$vo.aid}</td>-->
            <td width="60">{$vo.title}</td>
            {if($vo.typeid==4)}
            <td width="90"><img src="{$vo.attachment}" style="width:150px;"></td>
            {elseif($vo.typeid==2)/}
            <td width="90"><video src="{$vo.attachment}" style="width:150px;" controls="controls"></video></td>
            {elseif($vo.typeid==3)/}
            <td width="90"><audio src="{$vo.attachment}" style="width:250px;" controls ></audio></td>
            {else/}
            <td width="90">---</td>
            {/if}

        </tr>
        {/volist}
        </tbody>
    </table>
</div>
/*--js获取点击表格便选中当前行--*/
$(function() {
    $('table').on('click', 'tr', function(e){
        // 获取table中所有的行
        var trs = $(this).parent('tbody').find('tr');
        // 取消所有行的选中
        $.each(trs, function(index, item) {
        // 如果在此使用的是attr()设置选中状态,取消后将不能设置为选中
            $(item).find('td:eq(0) input').prop('checked', false);
        });
        // 选中当前点击的行
        $(this).find('td:eq(0) input').prop('checked',true)
        var selectid = $("input[type='radio']:checked").val();   //选中行id值
        var typeid="{$assignData['typeid']}";
        if(typeid==1){
            layer.msg('成功选择!',{icon:1,time:1000});
            setTimeout(function() {
                act_reload(selectid,typeid);
            }, 1000);

        }else if(typeid==2){
            layer.msg('成功选择视频ID='+selectid,{icon:1,time:1000});
            setTimeout(function() {
                act_reload(selectid,typeid);
            }, 1000);
        }else if(typeid==3){
            layer.msg('成功选择音频ID='+selectid,{icon:1,time:1000});
            setTimeout(function() {
                act_reload(selectid,typeid);
            }, 1000);
        }else{
            layer.msg('成功选择图片ID='+selectid,{icon:1,time:1000});
            setTimeout(function() {
                act_reload(selectid,typeid);
            }, 1000);
        }

    })
});

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值