【问题标题】:Table + form not submitting表格+表格未提交
【发布时间】:2014-09-12 17:18:11
【问题描述】:

在我进一步尝试制作相关数据库时,我遇到了奇怪的(至少对我而言)我的表单没有提交任何值的问题。我的祝福将流向任何帮助我在此代码中发现问题的人:

***in index.cshtml***
<form method = "get" action="update.cshtml" id="mainForm"></form>
    <table class="database">
       <tr>
           <th>Ocena z informatyki</th>
           <th>Ocena z fizyki</th>
           <th>Ocena z matematyki</th>
           <th>No.</th>
       </tr> 
        @foreach(var row in db.Query(queryString)) 
        {
            <tr>
            <td id="it" ondblclick="edit(this)">@row.it</td>
            <td id="physics" ondblclick="edit(this)">@row.physics</td>
            <td id="math" ondblclick="edit(this)">@row.maths</td>
            <td id="no">@row.no</td>
            <td><button value="Submit changes" onclick="submit" form="mainForm">Submit changes</button></td>
            </tr>                
        }
        </table>

这里是“edit()”函数:

***in scripts.js***
function edit(elm) {
    if (elm.getElementsByTagName('input').length > 0) return;

    var value = elm.innerHTML;
    elm.innerHTML = '';

    var input = document.createElement('input');
    input.setAttribute('type', 'text');
    input.setAttribute('value', value);
    input.setAttribute('form', 'mainForm');
    elm.appendChild(input);
    input.focus();
}

【问题讨论】:

标签: javascript html asp.net-mvc forms razor


【解决方案1】:

如果您使用“method = get”提交表单,则需要将数据附加到查询字符串。

【讨论】:

    猜你喜欢
    • 2019-03-06
    • 2018-01-02
    • 2021-04-07
    • 2016-03-02
    • 1970-01-01
    相关资源
    最近更新 更多