简体   繁体   English

如何在表格行中生成动态按钮并在单击按钮时打开新页面

[英]How to generate Dynamic button in a table row and open new page on button click

i actually having a requirement of generating dynamic table from services url and after that generating dynamic table.This is i worked it out but what i want is 我实际上有一个从服务url生成动态表的要求,然后再生成动态表。这是我解决了,但我想要的是

  1. How to generate a dynamic button on each table row with click event. 如何使用click事件在每个表行上生成一个动态按钮。
  2. After generating the button how we can assign click events to the button i mean suppose in a table there are four columns like date,id number,name,location and on the clicking on the each column or related to that cell it has to redirect to a new page. 生成按钮后,我们如何将点击事件分配给按钮,我的意思是假设一个表中有四列,例如日期,ID号,名称,位置,并且在每列上单击或与之相关时,它必须重定向到该单元格一个新页面。

or 要么

  1. if a table row is clicked and there are 4 columns are there like date,id number,name,location the click event has will take date as a parameter and click event function and then it have to proceed to the next page/redirect 如果单击表行,并且有4列,如日期,id号,名称,位置,则click事件具有的日期将以date为参数,并具有click事件功能,然后必须进入下一页/重定向

     $('#btn_Day').click(function () { var ex = document.getElementById("dpp_info"); var clOptions = ex.options[ex.selectedIndex].value; var clOptions1 = ex.options[ex.selectedIndex].text; var dt = todaydate; var dt1 = todaydate; $.ajax({ type: 'GET', url: xxxxx.xxxxx.xxxxx, data: frmDate_=" + dt + "&toDate_=" + dt1 + "", success: function (resp) { var Location = resp; var tr; for (var i = 0; i < Location.length; i++) { tr = tr + "<tr>"; tr = tr + "<td style='height:20px' align='left'>" + Location[i].Name + "</td>"; tr = tr + "<td style='height:20px' align='left'>" + Location[i].Date + "</td>"; tr = tr + "<td style='height:20px' align='left'>" + Location[i].IdNum + "</td>"; tr = tr + "</tr>"; }; document.getElementById('Wise').innerHTML = "<table class='r'>" + "<tr><thead ><th style='height:20px'>Location</th>" + "<th style='height:20px'>Date</th>" + "<th style='height:20px'>Id Num</th>" + "</tr></thead>" + tr + "<tr></tr>" + "</table>"; document.getElementById('Wise').childNodes[0].nodeValue = null; }, error: function (e) { window.plugins.toast.showLongBottom("Please Enable your Internet connection"); } }); }); 

    在此处输入图片说明

now in the image if u see there are four columns suppose if i click on the idnumb and there records related to that particular number has to be displayed in separate page 现在在图像中,如果您看到有四列,假设我单击idnumb,并且与该特定编号相关的记录必须在单独的页面中显示

Looking For Help! 寻找帮助!

After some more discussion on this the key was to just use the handler and pass any values using attributes. 在对此进行更多讨论之后,关键是仅使用处理程序并使用属性传递任何值。 You can see the fiddle here 你可以在这里看到小提琴

https://jsfiddle.net/p2fpbkuo/3/ https://jsfiddle.net/p2fpbkuo/3/

$('.button-click').off();
$('.button-click').on('click', function () {
    // navigate to new page
 // console.log('button click')

 // what you could do here is get the serialnumber which is an attribute on the button 
 var id = $(this).attr('data-id') // as long as this is unique this should always work

 var filteredResults = results.filter(function (result) {
  if (result.SerialNumber.toString() === id.toString()) {
    return result;
  }
});

var selectedRowValues = filteredResults[0];

// this will contain all the values for that row
console.log(selectedRowValues)

 // var dataValue = $(this).attr('data-url'); // dont't need this any more
 window.open(selectedRowValues.Url)
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM