Javascript 使用Jquery从输入中获取值
对于这类问题,我已经找到了很多答案,但没有一个能解决问题。 我甚至有一段非常相似的代码可以工作。但是,这会不断给出一个Javascript 使用Jquery从输入中获取值,javascript,jquery,html,Javascript,Jquery,Html,对于这类问题,我已经找到了很多答案,但没有一个能解决问题。 我甚至有一段非常相似的代码可以工作。但是,这会不断给出一个NaN。我已经把范围缩小到无法获得 var or = parseFloat($(this).siblings("input[name='or']").val()); 这是我的。 非常感谢您的帮助 <tbody> {% for i in t %} <tr class="hotlines"> <td><strong>{
NaN
。我已经把范围缩小到无法获得
var or = parseFloat($(this).siblings("input[name='or']").val());
这是我的。
非常感谢您的帮助
<tbody>
{% for i in t %}
<tr class="hotlines">
<td><strong>{{i.owner}}</strong><br>{{i.owner_id}}</td>
<td>
<li>{{i.tot_itm}}</li>
<li>Per Piece Profit: {{"${:,.2f}".format(i.item_prof)}}</li>
</td>
<td>
<li>Payable Hotlines <br><input type="text" name="hln" maxlength="4" value=""></li>
<li>Per Hotline Profit: {{"${:,.2f}".format(i.hotline_prof)}}</li>
<input type="text" name="or" value="{{i.hotline_prof}}">
</td>
<td>
<li>Total Backpack Profit: {{"${:,.2f}".format(i.tot_prof)}}</li>
<li>Total Hotline Profit: <input type="text" name="hlnt" readonly /></li>
</td>
</tr>
<!-- Total items sent from db -->
<input class="hidden" type="text" name="it" value="{{i.tot_itm}}">
<!-- per hotline override from db -->
<!-- profit from all items * per item override sent from server -->
<input class="hidden" type="text" name="bp" value="{{i.tot_prof}}">
<!-- total proffit from items and hotlines -->
<input class="hidden" type="text" name="th">
<!-- per item override from db -->
<input class="hidden" type="text" name="or_it" value="{{i.item_prof}}">
<!-- total proffit from hotlines -->
<input class="hidden" type="text" name="hl" value="0">
<!-- organization ID -->
<input class="hidden" type="text" name="o" value="{{org.organization_ID}}">
<input class="hidden" type="text" name="owner_n" value="{{i.owner}}">
<input class="hidden" type="text" name="owner_id" value="{{i.id}}">
{% endfor %}
<td><button type="submit" class="btn btn-link btn-xs btn-block">Submit Report</button></td>
</tbody>
在Tyler Roper的指导下,这是一个与Javascript无关的简单修复。 我很累,正在测试一些东西,试图快速地将一个页面转换成一个表。 可怕的HTML就是原因。为了解决这个问题,我简单地改为:
<form action="/weekly_reports/" method="POST">
<table id="office_weekly" class="table table-hover table-striped">
<thead>
<th>Office</th>
<th>Backpacks</th>
<th>Hotlines</th>
<th>Total</th>
</thead>
<tbody>
{% for i in t %}
<tr class="hotlines">
<td><strong>{{i.owner}}</strong><br>{{i.owner_id}}</td>
<td>
{{i.tot_itm}}<br>
Per Piece Profit: {{"${:,.2f}".format(i.item_prof)}}
</td>
<td>
Payable Hotlines <br><input type="text" name="hln" maxlength="4" value=""><br>
Per Hotline Profit: {{"${:,.2f}".format(i.hotline_prof)}}<br>
<input type="hidden" name="or" value="{{i.hotline_prof}}">
</td>
<td>
Total Backpack Profit: {{"${:,.2f}".format(i.tot_prof)}}
</td>
<td>Total Hotline Profit: <input type="text" name="hlnt" readonly /></td>
</tr>
{% endfor %}
<td><button type="submit" class="btn btn-link btn-xs btn-block">Submit Report</button></td>
</tbody>
</table>
</form>
办公室
背包
热线
全部的
{t%中的i的%s}
{{i.owner}
{{i.owner\u id}
{{i.tot_itm}}
每件利润:{{${:,.2f}。格式(i.item_prof)}
付费热线
每热线利润:{{{${:,.2f}。格式(即热线教授)}}
背包利润总额:{{{${,.2f}。格式(i.tot_prof)}
热线电话利润总额:
{%endfor%}
提交报告
(1)事件附加到的元素[name='hln']
没有同级,因此$(此)。同级(…)
将找不到任何内容。(2) 你的HTML有点乱-你在
元素中有
元素,在
元素之间有
元素,等等。我应该注意,浏览器会尝试自行解决你的HTML错误,不可预测地改变元素,并可能在过程中创建同级。在继续之前,您需要先修复HTML,否则会带来很多麻烦。此外,您隐藏的输入不在单元格内,因此它们将在表外(取决于浏览器的实现)-您将有一大堆输入,所有输入都具有相同的名称,并与其原始行分离-将它们全部放在第一个/最后一个/隐藏单元格中。好的,这很有意义。我将修复HTML并重试。在我的沮丧中,我只是把东西到处都放@jesseCampeez确保通过验证器()传递HTML,以便创建正确有效的HTML结构。
<form action="/weekly_reports/" method="POST">
<table id="office_weekly" class="table table-hover table-striped">
<thead>
<th>Office</th>
<th>Backpacks</th>
<th>Hotlines</th>
<th>Total</th>
</thead>
<tbody>
{% for i in t %}
<tr class="hotlines">
<td><strong>{{i.owner}}</strong><br>{{i.owner_id}}</td>
<td>
{{i.tot_itm}}<br>
Per Piece Profit: {{"${:,.2f}".format(i.item_prof)}}
</td>
<td>
Payable Hotlines <br><input type="text" name="hln" maxlength="4" value=""><br>
Per Hotline Profit: {{"${:,.2f}".format(i.hotline_prof)}}<br>
<input type="hidden" name="or" value="{{i.hotline_prof}}">
</td>
<td>
Total Backpack Profit: {{"${:,.2f}".format(i.tot_prof)}}
</td>
<td>Total Hotline Profit: <input type="text" name="hlnt" readonly /></td>
</tr>
{% endfor %}
<td><button type="submit" class="btn btn-link btn-xs btn-block">Submit Report</button></td>
</tbody>
</table>
</form>