// 回到顶部
$(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属性里面,等触发事件直接可以得到。