js中使用document.createElement()创建按钮的时候如何让传递参数

本文介绍了一种使用JavaScript实现的材料删除功能,该功能通过AJAX进行后台交互,完成材料的在线删除操作,并能根据反馈结果刷新页面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var tdcaozuo = document.createElement('td');
   tdcaozuo.align="center";
//设置id
tdcaozuo.setAttribute('id', 'td'+data.cllist[i].id);

$("#td"+a).append('<button onclick=delmater("'+a+'") id="buttonidb">删除</button>');

<script type="text/javascript">
    function delmater(did){
        $.ajax({
             url: "${servePath}/pc/wuye/delmater",
                data:{
                    "id":did,
                },
                type:"post",
                success : function(data) {
                   if (data=="true") {
                        alert("材料删除成功");
                        window.location.reload();
                    }else{
                        alert("材料删除失败");
                         window.location.reload();
                    }
                }
         });
    }
</script>
``` // 更新分页控件 function updatePagination(totalPages, currentPage) { const paginationContainer = document.getElementById('pagination'); paginationContainer.innerHTML = ''; if (currentPage > 1) { const prevBtn = document.createElement('button'); prevBtn.textContent = '上一页'; prevBtn.onclick = () => { currentPage--; loadData(); }; paginationContainer.appendChild(prevBtn); } let startPage, endPage; if (totalPages <= 5) { startPage = 1; endPage = totalPages; } else { startPage = Math.max(1, currentPage - 2) endPage = Math.min(totalPages, currentPage + 2); } if (startPage > 1) { const firstPageBtn = document.createElement('button'); firstPageBtn.textContent = '1'; firstPageBtn.onclick = () => { currentPage = 1; loadData(); }; paginationContainer.appendChild(firstPageBtn); if (startPage > 2) { const ellipsisStart = document.createElement('span'); ellipsisStart.textContent = '...'; paginationContainer.appendChild(ellipsisStart); } } for (let i = startPage; i <= endPage; i++) { const pageBtn = document.createElement('button'); pageBtn.textContent = i; if (i === currentPage) { pageBtn.style.backgroundColor = '#ddd'; } pageBtn.onclick = () => { currentPage = i; loadData(); }; paginationContainer.appendChild(pageBtn); } if (endPage < totalPages) { if (endPage < totalPages - 1) { const ellipsisEnd = document.createElement('span'); ellipsisEnd.textContent = '...'; paginationContainer.appendChild(ellipsisEnd); } const lastPageBtn = document.createElement('button'); lastPageBtn.textContent = totalPages; lastPageBtn.onclick = () => { currentPage = totalPages; loadData(); }; paginationContainer.appendChild(lastPageBtn); } if (currentPage < totalPages) { const nextBtn = document.createElement('button'); nextBtn.textContent = '下一页'; nextBtn.onclick = () => { currentPage++; loadData(); }; paginationContainer.appendChild(nextBtn); } // 添加跳转输入框 const gotoInput = document.createElement('input'); gotoInput.type = 'number'; gotoInput.min = '1'; gotoInput.max = totalPages; gotoInput.placeholder = '跳转到...'; gotoInput.style.marginLeft = '10px'; gotoInput.style.width = '50px'; paginationContainer.appendChild(gotoInput); const gotoBtn = document.createElement('button'); gotoBtn.textContent = '跳转'; gotoBtn.onclick = () => { const page = parseInt(gotoInput.value, 10); if (page >= 1 && page <= totalPages) { currentPage = page; loadData(); } }; paginationContainer.appendChild(gotoBtn); }```A form field element should have an id or name attribute
最新发布
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值