簡體   English   中英

基本Javascript:使用onclick來打印表格

[英]Basic Javascript : using onclick to print a table

 <!DOCTYPE html> <html> <head> <title> Title </title> <style type="text/css"> table.tableizer-table { border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px; } .tableizer-table td { padding: 4px; margin: 3px; border: 1px solid #ccc; } .tableizer-table th { background-color: #104E8B; color: #FFF; font-weight: bold; } </style> </head> <body> Please select your price range (per hour) : <select id="valueDropdown"> <option value="lessThanFive">below 5</option> <option value="betweenSixAndTen">6-10</option> <option value="tenPlus">10+</option> </select> <button type="button" onclick="toggleTable();" >Search</button> <div id="cheapestTable" style="display: none;> <table class="tableizer-table" > <tr class="tableizer-firstrow"><th>SCHOOLS</th><th>Booking </th><th>web site</th><th> Price per hour </th><th> Columna1 </th><th>Courses English</th><th>Language</th><th>Social Media</th><th>Location</th></tr> <tr><td>Brittannia</td><td>no</td><td>7</td><td> £4.00 </td><td>&nbsp;</td><td>General, Examn, 1to1, Business</td><td>English</td><td>&nbsp;</td><td>Manchester</td></tr> <tr><td>ABLE</td><td>no</td><td>8</td><td> £5.00 </td><td>&nbsp;</td><td>General, Examn, 1to1</td><td>English Spanish</td><td>F, T, S, in, I</td><td>Manchester</td></tr> </table> </div> <script> function toggleTable(){ var e = document.getElementById("valueDropdown"); if(e.options[e.selectedIndex].value === 'lessThanFive'){ document.getElementById('cheapestTable').style.display = "table" }else{ document.getElementById('result').innerHTML="hi2"; } } </script> </body> </html> 

我試圖在用戶按下按鈕時使用Javascript打印表格。 該按鈕工作正常。

該表非常復雜。 到目前為止,我已經嘗試過將桌子的原始位置設置在屏幕之外,然后在用戶按下按鈕時將其放回原處。

表:

<div id="cheapestTable">
<style type="text/css">
    table.tableizer-table {
    border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
 position: absolute ;
   top: -99px;
   left: -99px;
}

..更多關於單個單元格的格式化等信息。

然后,當按下按鈕時:

document.getElementById('cheapestTable').style.tableizer-table.left = "100px";
document.getElementById('cheapestTable').style.tableizer-table.top = "100px";

但是,當按下按鈕時,表格不會出現。

您在<div id="cheapestTable" style="display: none;>缺少結束語。

另外,顯示DIV的適當樣式是block而不是table

 function toggleTable() { var e = document.getElementById("valueDropdown"); if (e.options[e.selectedIndex].value === 'lessThanFive') { document.getElementById('cheapestTable').style.display = "block" } else { document.getElementById('result').innerHTML = "hi2"; } } 
 table.tableizer-table { border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px; } .tableizer-table td { padding: 4px; margin: 3px; border: 1px solid #ccc; } .tableizer-table th { background-color: #104E8B; color: #FFF; font-weight: bold; } 
 Please select your price range (per hour) : <select id="valueDropdown"> <option value="lessThanFive">below 5</option> <option value="betweenSixAndTen">6-10</option> <option value="tenPlus">10+</option> </select> <button type="button" onclick="toggleTable();">Search</button> <div id="cheapestTable" style="display: none;"> <table class="tableizer-table "> <tr class="tableizer-firstrow "> <th>SCHOOLS</th> <th>Booking</th> <th>web site</th> <th>Price per hour</th> <th>Columna1</th> <th>Courses English</th> <th>Language</th> <th>Social Media</th> <th>Location</th> </tr> <tr> <td>Brittannia</td> <td>no</td> <td>7</td> <td>£4.00</td> <td>&nbsp;</td> <td>General, Examn, 1to1, Business</td> <td>English</td> <td>&nbsp;</td> <td>Manchester</td> </tr> <tr> <td>ABLE</td> <td>no</td> <td>8</td> <td>£5.00</td> <td>&nbsp;</td> <td>General, Examn, 1to1</td> <td>English Spanish</td> <td>F, T, S, in, I</td> <td>Manchester</td> </tr> </table> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM