2017-07-22 45 views
0

我實際上有一個要求,從服務url生成動態表,然後生成動態表。這是我工作,但我想要的是如何在表格行中生成動態按鈕並在按鈕上單擊打開新頁面

  1. 如何使用點擊事件在每個表格行上生成動態按鈕。
  2. 生成按鈕後,我們如何分配點擊事件按鈕我的意思是假設在一個表中有四個列,如日期,身份證號碼,名稱,位置和點擊每列或與該單元格相關它必須重定向到一個新頁面。

  • 如果一個錶行被點擊和有4列有喜歡日期,ID號,名稱,位置點擊事件具有將採取日期作爲參數,然後單擊事件函數,然後必須再進行下一頁/重定向

    $('#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"); 
    
        } 
    }); 
    }); 
    

    enter image description here

  • 現在

    圖像中,如果你看到有四列,如果我在idnumb點擊,有記錄與特定數量必須顯示在單獨的頁面

    尋求幫助想!

    +1

    不知道我完全理解你想要做什麼,但它聽起來像你想添加處理日期,身份證號碼,姓名和位置的小提琴。你可以添加一個類到列/行和你需要的任何其他屬性,如data-name ='number'。一旦你將這個添加到dom中,你可以添加該類的處理程序? –

    +0

    @JamesDale請檢查問題 – Madpop

    +0

    因此,如果我點擊22,它會顯示IdNum爲22的其他記錄? –

    回答

    1

    經過對此的更多討論後,關鍵是隻使用處理程序並使用屬性傳遞任何值。你可以在這裏看到

    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) 
    }); 
    
    相關問題