添加模型显示“是”到一个 jscript 函数,该函数从值“1”的单选按钮输入中获取总计
关于如何解决以下问题有什么想法吗?
编辑-似乎有些人不理解标题和代码中的问题,所以这里是,每次更改页面上的单选按钮时,我的运行总计都会增加,但我有 4 个带有单选按钮的表单,每个表单保存后有一个显示视图而不是编辑,我的问题是我不知道如何最好地将显示值放入我的总函数中。 另外,在显示视图中,我有两种不同的方式来显示我的问题,切换为 3 种形式,其余为最终形式。
Edit2-注意到有些人认为如果代码就是他们在页面顶部看到的所有内容,那么有些人就不会向下阅读文本,因此将其移至顶部以希望使其更清晰
编辑视图
<td class="aCell">
<%= Html.RadioButton(i+"_1", "1", new { @onclick = "getTotal()", @class = "sectionCB" }) %>
</td>
<td class="aCell">
<%= Html.RadioButton(i+"_1", "0", new { @onclick = "getTotal()", @class = "sectionCB", @checked = "checked" })%>
显示视图
switch (i)
{
case 1:
{
qna1 = (Model.Q1A1) ? "Yes" : "No";
qna2 = (Model.Q1A2) ? "Yes" : "No";
break;
}
<tr>
<td class="bCell" >
H/k
</td>
<td class="aCell" colspan="2"><%: (Model.Q9A1) ? "Yes" : "No"%></td>
总功能
function getTotal() {
var $inputs = $('#dAnswers :input.sectionCB');
var x = 0;
$inputs.each(function () {
if ($(this).val() == "1" && $(this).attr('checked')) { x++; }
});
var total = Math.round(x / 51 * 100);
$('#sTotal').html(total + '%');
}
总显示
<span style="font-size: 250%;" id="sTotal">0%</span>
any ideas on how to resolve whats below?
Edit- seems some people don't understand the issue from the title and the code so here it is, I have a running total which increases each time a radio button on my page is changed but I have 4 forms which have radio buttons and each after being saved has a display view instead of edit, my issue is I don't know how best to get the display value into my total function.
Also in the display view I have the 2 different ways in which my questions are displayed, switch for 3 forms and rest for final form.
Edit2- Noticed that some people think if code is all they see at the top of page then some don't read down to text so moving it up to top in hopes of making it clearer
Edit view
<td class="aCell">
<%= Html.RadioButton(i+"_1", "1", new { @onclick = "getTotal()", @class = "sectionCB" }) %>
</td>
<td class="aCell">
<%= Html.RadioButton(i+"_1", "0", new { @onclick = "getTotal()", @class = "sectionCB", @checked = "checked" })%>
Display view
switch (i)
{
case 1:
{
qna1 = (Model.Q1A1) ? "Yes" : "No";
qna2 = (Model.Q1A2) ? "Yes" : "No";
break;
}
<tr>
<td class="bCell" >
H/k
</td>
<td class="aCell" colspan="2"><%: (Model.Q9A1) ? "Yes" : "No"%></td>
Total function
function getTotal() {
var $inputs = $('#dAnswers :input.sectionCB');
var x = 0;
$inputs.each(function () {
if ($(this).val() == "1" && $(this).attr('checked')) { x++; }
});
var total = Math.round(x / 51 * 100);
$('#sTotal').html(total + '%');
}
Total display
<span style="font-size: 250%;" id="sTotal">0%</span>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论