回到顶部 jquery 动态添加表 事件委托

// 回到顶部
	$(window).scroll(function () {
		if ($(window).scrollTop() >= 50) {
			$('#back').fadeIn();
		}
		else {
			$('#back').fadeOut();
		}
	})
	$('#back').click(function () {
		$('html,body').animate({ scrollTop: 0 }, 500);
	});

$("#back")是获取回到顶部的按钮。

 

var table_title = $("<h3 class='center-td'>需求功能表</h3>")
    table_title.appendTo($('#text-box'))
    var table = $("<table>").addClass('text_table').attr('cellpadding', '0').attr('cellspacing', '0')
    var tbody = $("<tbody>").appendTo(table)
    tbody.append($("<tr>").
      append($('<th>').html('项目名称')).
      append($('<th>').html('已有功能名称')).
      append($('<th>').html('已有功能描述')).
      append($('<th>').html('系统名称')).
      append($('<th>').html('功能部门')).
      append($('<th>').html('相似度')).
      append($('<th>').html('操作')))

    $.each(data.similar_functions, function (idx, list) {
      if (list.function_des.length > 50) {
        list.function_des1 = getName(list.function_des.substring(0, 50) + '...' + '<span class="des-more" data-id=' + idx + '>More<span>', list.keywords)
        list.function_des2 = getName(list.function_des + '<span class="des-back"  data-id=' + idx + '>收起<span>', list.keywords)
      } else {
        list.function_des1 = list.function_des
        list.function_des2 = list.function_des
      }
    })
    $.each(data.similar_functions, function (idx, list) {
      if (idx < 5) {
        tbody.
          append(
            $("<tr>").
              append($('<td>').html(list.project_name)).
              append($('<td>').html(getName(list.function_name, list.keywords))).
              append($('<td>').html(list.function_des1).attr('data-des1', list.function_des1).attr('data-des2', list.function_des2)).
              append($('<td>').html(list.function_system)).
              append($('<td>').html(list.func_department)).
              append($('<td>').html((list.similarity * 100).toFixed(2) + '%')).
              append($('<td>').append($('<button>').html('查看详情').addClass('td-btn').attr('data-id', idx)))
          )
      } else {
        tbody.
          append(
            $("<tr>").addClass('tr-back').css('display', 'none').
              append($('<td>').html(list.project_name)).
              append($('<td>').html(getName(list.function_name, list.keywords))).
              append($('<td>').html(list.function_des1).attr('data-des1', list.function_des1).attr('data-des2', list.function_des2)).
              append($('<td>').html(list.function_system)).
              append($('<td>').html(list.func_department)).
              append($('<td>').html((list.similarity * 100).toFixed(2) + '%')).
              append($('<td>').append($('<button>').html('查看详情').addClass('td-btn').attr('data-id', idx)))
          )

      }
    })
$("#file-box").on("click", ".des-more-file", function (event) {
    console.log('点击more')
    var idx = $(event.target).attr('data-id')
    var con = $(event.target).parent().attr('data-des2')
    $(event.target).parent().html(con)
  })
  $("#file-box").on("click", ".des-back-file", function (event) {
    console.log('点击收起')
    var idx = $(event.target).attr('data-id')
    var con = $(event.target).parent().attr('data-des1')
    $(event.target).parent().html(con)
    
  })

如果想获取一些什么参数的话,可以加到attr属性里面,等触发事件直接可以得到。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值