添加模型显示“是”到一个 jscript 函数,该函数从值“1”的单选按钮输入中获取总计

发布于 2024-10-08 03:31:54 字数 1749 浏览 0 评论 0原文

关于如何解决以下问题有什么想法吗?

编辑-似乎有些人不理解标题和代码中的问题,所以这里是,每次更改页面上的单选按钮时,我的运行总计都会增加,但我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文