![](/img/trans.png)
[英]How I can pass variables from Flex to JavaScript (separate HTML file) and return the other variables?
[英]How to put javascript variables into an HTML table from a separate Javascript file?
所以我正在努力適應電子。 我設置了一個 HTML 表,在一個單獨的 js 文件中,我有從用戶表單中獲取的變量。 我需要弄清楚如何將這些變量放入 html 表中。
這是 html :
<script src="./index.js"></script>
<script type="text/javascript" src="add.js"></script>
<font size="3" face="Courier New">
<table style="width:100%">
<tr>
<th>Name of Item</th>
<th>Size</th>
<th>Purchase Amount</th>
<th>Sold Amount</th>
<th>Platform Sold</th>
<th>Total Fees</th>
<th>Total Profit</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
這是表單的html文件:
<body>
<div class="container">
<div class="columns">
<div class="column col-10">
<h1 class="text-center">New Sale</h1>
<form id="todoForm">
<div class="form-group">
<label class="form-label" for="add-input">Name of Item</label>
<input class="form-input" type="text" name="add-input" placeholder="Jordan 1..." id="itemName">
<label class="form-label" for="add-input">Size</label>
<input class="form-input" type="text" name="add-input" placeholder="Large..." id="size">
<label class="form-label" for="add-input">purchase Amount</label>
<input class="form-input" type="text" name="add-input" placeholder="$160..." id="pAmount">
<label class="form-label" for="add-input">price Sold</label>
<input class="form-input" type="text" name="add-input" placeholder="$400..." id="sAmount">
<label class="form-label" for="add-input">platform Sold</label>
<input class="form-input" type="text" name="add-input" placeholder="StockX..." id="platform">
</div>
<button class="btn">Add Sale</button>
</form>
</div>
</div>
</div>
<script src="./add.js"></script>
</body>
</html>
這是javascript文件:
const { ipcRenderer } = require('electron')
var itemName = document.getElementById("itemName");
var size = document.getElementById("size");
var pAmount = document.getElementById("pAmount");
var sAmount = document.getElementById("sAmount");
var platform = document.getElementById("platform");
感謝所有幫助!
您可以執行以下操作:
代碼
<tr>
<td id = "name"></td>
<td id = "size-cell"></td>
...
</tr>
document.getElementById('name').innerHTML = itemName.value;
document.getElementById('size-cell').innerHTML = size.value;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.