首先感謝大神能夠點進來,先謝謝啦~~
是這樣的,我們這里需要制作一個網頁,其實就是個表格,有幾項(文本)是必填內容,填好不用上傳服務器,在頁面上做一個列印按鈕,直接列印A4紙就可以了,固定大小,只有一頁,做表格我會,不會弄輸入框,和列印內容,求大神指教~~我是小白,一點不懂,求講的簡單易懂些

再次感謝
uj5u.com熱心網友回復:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3個meta標簽*必須*放在最前面,任何其他內容都*必須*跟隨其后! -->
<title>興趣愛好</title>
</head>
<style>
.a4-endwise{
width: 1075px;
height: 1567px;
border: 1px #000 solid;
overflow: hidden;
padding: 0;
word-break: break-all;
font-size-adjust: 10;
}
.a4-broadwise{
width: 1569px;
height: 1073px;
border: 1px #000 solid;
overflow: hidden;
padding: 0;
word-break:break-all;
}
.print{
position: fixed;
top: 1%;
right: 10%;
}
</style>
<body>
<!--startprint-->
<form name="form1" id="form1" target="new">
<div class="container a4-endwise" id="test">
<!--//以下輸入正式內容-->
<p align="right" ><strong><font font-family="宋體" size="22" >三年級</font></strong><strong><font font-family="宋體" size="14" >二班</font></strong></p>
<p > </p>
<div align="center">
<table width="980" height="451" border="2">
<tr>
<td width="41" rowspan="4"><p align="center" ><p align="center" >個 </p>
<p align="center" >人 </p>
<p align="center" >信 </p>
<p align="center" >息 </p></td>
<td height="180" colspan="3"><p ><br>
了解方式:<input type="checkbox"/>網路<input type="checkbox""/>海報 <input type="checkbox"/>聽說<br>
姓名:
<input name="姓名" cols="40" rows="1" type="text" required id="xingming" style="width:325px;height:17px;"></textarea>
<br>
班級:
<input name="班級" cols="40" rows="1" type="text" required id="banji" style="width:325px;height:17px;"></textarea>
<br>
<br>
興趣愛好:<input type="checkbox"/>閱讀<input type="checkbox"/>球類(<input type="checkbox""/>足球<input type="checkbox"/>籃球)<input type="checkbox"/>游戲</p></td>
</tr>
<tr>
<td height="32" colspan="3"> </td>
</tr>
<tr>
<td width="451" height="35"> </td>
<td width="207"> </td>
<td width="251"> </td>
</tr>
<tr>
<td height="190"> </td>
<td> </td>
<td> </td>
</tr>
</table>
第一<input type="submit" value="https://bbs.csdn.net/topics/檢查表格是否完整">
第二<input type="submit" onclick="preview();" value="https://bbs.csdn.net/topics/列印" href="javascript:;"/>
</div>
<p > </p>
</div>
</div>
</form>
<div align="center">
<!--endprint-->
<script>
/**
* [提交列印]
* @return {[type]} [description]
*/
function preview()
{
bdhtml=window.document.body.innerHTML;//獲取當前頁的html代碼
sprnstr="<!--startprint-->";//設定列印開始區域
eprnstr="<!--endprint-->";//設定列印結束區域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //從開始代碼向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//從結束代碼向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
}
</script>
</div>
</body>
</html>
uj5u.com熱心網友回復:
代碼是這樣的,我不懂都是從網上找的,想法是,做成一頁A4紙,用戶填入必要資訊,然后自己列印出來,現在是文本框輸入后,一列印就沒有輸入內容了,而且我想列印時只列印輸入的內容,不列印那個輸入的方框,還有就是下面的按鈕,能不能列印的同時檢查填寫是否完整呢,不完整就不列印,請大家指教uj5u.com熱心網友回復:
哪位大神來幫幫忙啊
uj5u.com熱心網友回復:
獲取innerHTML的值不會包含用戶在文本框輸入的內容,你重寫了document.body.innerHTML 用戶輸入的內容當然沒有了。你不用重寫document.body.innerHTML,有不需要列印的部分可以用<style type="text/css" media="print"></style>單獨設定列印的樣式。
如不列印輸入的方框和下面的按鈕
<style type="text/css" media="print">
.noprint { display: none; }
input[type="text"] { border-color: transparent; }
</style>
<div class="noprint">
第一<input type="submit" value="https://bbs.csdn.net/topics/檢查表格是否完整">
第二<input type="submit" onclick="preview();" value="https://bbs.csdn.net/topics/列印" href="javascript:;"/>
</div>
uj5u.com熱心網友回復:
檢查填寫是否完整可以去看看表單驗證的相關js代碼uj5u.com熱心網友回復:
這個問題聽著沒那么復雜,直接呼叫window.print()不就行了uj5u.com熱心網友回復:
不列印那個輸入的方框可以提交到后臺后,回傳重新生成需要的頁面
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/104021.html
標籤:HTML(CSS)
上一篇:WinWebMail相關問題
下一篇:請教mouseover效果
