php - Clickable row with link -


How can I make every row clickable without repetition

This is an example that shows the problem, Parameter may be code:

  & lt; Table & gt; & Lt; Thead & gt; & Lt; TR & gt; & Lt; Th & gt; Code & lt; / Th & gt; & Lt; Th & gt; Users & lt; / Th & gt; ... & lt; / Tr & gt; & Lt; / Thead & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; Td> & Lt; A href = "page / 123" & gt; 123 & lt; / A & gt; & Lt; / Td> & Lt; Td> & Lt; A href = "page / 123" & gt; User A & lt; / A & gt; & Lt; / Td> ... & lt; / Tr & gt; & Lt; TR & gt; & Lt; Td> & Lt; A href = "page / 456" & gt; 456 & lt; / A & gt; & Lt; / Td> & Lt; Td> & Lt; A href = "page / 456" & gt; User B & lt; / A & gt; & Lt; / Td> ... & lt; / Tr & gt; & Lt; / Tbody & gt;  

Sorry for my english, I hope you understand the problem.

There are a few different ways to achieve this. Here are some plain javascript and a jQuery using.

Plain JS

Use just onclick parameters with side javascript very straight forward.

  & lt; Table & gt; & Lt; Thead & gt; & Lt; TR & gt; & Lt; Th & gt; Code & lt; / Th & gt; & Lt; Th & gt; Users & lt; / Th & gt; ... & lt; / Tr & gt; & Lt; / Thead & gt; & Lt; Tbody & gt; & Lt; Tr onclick = "window.location = 'page / parameter1';" & Gt; & Lt; TD & gt; 123 & lt; / Td> & Lt; TD & gt; User A & lt; / Td> ... & lt; / Tr & gt; & Lt; Tr onclick = "window.location = 'page / parameter2';" & Gt; & Lt; TD & gt; 456 & lt; / Td> & Lt; TD & gt; User B & lt; / Td> ... & lt; / Tr & gt; & Lt; / Tbody & gt; & Lt; / Table & gt;  

jQuery

You add a square with jQuery so that you can use it as that selector. There will also be a data-href parameter which will create the URL that you want the user to click on the row.

  & lt; Table & gt; & Lt; Thead & gt; & Lt; TR & gt; & Lt; Th & gt; Code & lt; / Th & gt; & Lt; Th & gt; Users & lt; / Th & gt; ... & lt; / Tr & gt; & Lt; / Thead & gt; & Lt; Tbody & gt; & Lt; Tr class = "clickable" data-href = "page / parameter1" & gt; & Lt; TD & gt; 123 & lt; / Td> & Lt; TD & gt; User A & lt; / Td> ... & lt; / Tr & gt; & Lt; Tr class = "clickable" data-href = "page / parameter2" & gt; & Lt; TD & gt; 456 & lt; / Td> & Lt; TD & gt; User B & lt; / Td> ... & lt; / Tr & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; Script & gt; JQuery (document) .ready (function ($) {$ ("tr.clickable"). Click (function () {window.location = $ (this) .data ("href");});}); & Lt; / Script & gt;  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -