Javascript Jquery检索表单所选选项文本和打印表
我想打印包含所有输入值和所选选项文本的表单。它适用于其余的文本和数字输入,但问题在于选择选项。无论选择哪个选项,它都只打印下拉列表中的第一个选项(T4+T4)。我希望它打印所选选项中的文本Javascript Jquery检索表单所选选项文本和打印表,javascript,jquery,html,printing,Javascript,Jquery,Html,Printing,我想打印包含所有输入值和所选选项文本的表单。它适用于其余的文本和数字输入,但问题在于选择选项。无论选择哪个选项,它都只打印下拉列表中的第一个选项(T4+T4)。我希望它打印所选选项中的文本 <div id="printContent"> <table border="1" class="css-serial" id="POITable"> <!-- Rand Titlu --> <tr>
<div id="printContent">
<table border="1" class="css-serial" id="POITable">
<!-- Rand Titlu -->
<tr>
<th>Nr</th>
<th>Latime (mm)</th>
<th>Lungime (mm)</th>
<th>Cantitate</th>
<th>Material</th>
<th>Client</th>
<th>Suprafata (m2)</th>
<th>Total (€)</th>
<th>Sterge</th>
</tr>
<!-- Rand 1 formular -->
<tr class="item">
<td>1</td>
<td><input id="latime_sticla" type="number" class="form-control lat amount" value=""></td>
<td><input id="lungime_sticla" type="number" class="form-control lung amount" value=""></td>
<td><input type="number" class="form-control cant amount" value=""></td>
<td>
<select id="materialSticla" name="material" class="form-control price amount" onchange="calculPret()">
<option value="13.5">T4+T4</option>
<option value="14.5">T4+Low</option>
<option value="16.1">T4+4 Anotimpuri</option>
<option value="18.5">T4+P</option>
<option value="20.8">T4+Stopsol</option>
<option value="16.5">T4+Niagara Alb</option>
<option value="14.7">T4+Delta Alb</option>
<option value="15.5">T4+Diamant</option>
<option value="15.5">T4+Krizet</option>
<option value="16.5">T4+Cincilla Alb</option>
<option value="19.5">T4+Niagara Bronz</option>
<option value="19.5">T4+Delta Bronz</option>
<option value="19.5">T4+Cincilla Bronz</option>
<option value="19.8">Oglinda+Oglinda</option>
<option value="21.5">Oglinda+Mat Alb</option>
<option value="24.5">Oglinda+Mat Bronz</option>
<option value="24.21">T4+T4+4 Anotimpuri</option>
<option value="25.6">T4+4 Anotimpuri+Low</option>
<option value="26.8">T4+T4+Mat Alb</option>
<option value="27.8">T4+T4+Mat Bronz</option>
<option value="29.6">T4+4 Anotimpuri + Mat Alb</option>
<option value="30.6">T4+4 Anotimpuri + Mat Bronz</option>
</select>
</td>
<td><input type="text" class="form-control" value=""></td>
<td><input type="text" name="suprafata" class="form-control totals" id="totals" value=""readonly="readonly"></td>
<td><input type="text" name="total" class="form-control total" id="total1" value=""readonly="readonly"></td>
<td><input type="button" class="btn btn-danger" id="delPOIbutton" value=" - " onclick="deleteRow(this)"/></td>
</tr>
</table>
</div>
我相信您的目标是确保在将表的内容写入新窗口时,将在新窗口中选择所选的值。 因此,换句话说,您需要确保用户选择的
标记上存在'selected'
属性
因此:
说明:
$(this.options).removeAttr('selected');
从上一个选择中删除所选的
属性,然后
$(this.options[this.selectedIndex]).attr('selected', 'selected');
将选定的属性添加到新选定的
希望这有帮助。添加您的calculPret()
code我编辑了帖子您想打印什么n在哪里?我想在打印机上打印页面中的表格,或者另存为pdf,就像按ctrl+p键一样。一切都很好,但选择框保持不变,不管你选择什么选项,看看图片你的意思是你想要选择后的简单文本,对吗?
$(this.options).removeAttr('selected');
$(this.options[this.selectedIndex]).attr('selected', 'selected');