MVC 将数据从表移动到输入

发布于 2024-12-19 20:57:40 字数 1233 浏览 2 评论 0原文

我正在尝试将数据从表中的选定行移动到 MVC 中的表单。我正在使用 jquery click 事件从我的表中检索数据并将其移动到我的表单中。单击事件正在运行,但它将数据移动到错误的字段。点击功能如下:

$(document).ready(function () {
    $(".innerTbltr").click(function () {
        alert("Event handle.");
        //this.css("background-color", "#E8EEF4");
        $("#firstName").val(this.childNodes[0].innerHTML);
        $("#lastName").val(this.childNodes[1].innerHTML);
        $("#address1").val(this.childNodes[2].innerHTML);
        $("#address2").val(this.childNodes[3].innerHTML);
        $("#city").val(this.childNodes[4].innerHTML);
        $("#state").val(this.childNodes[5].innerHTML);
        $("#zip").val(this.childNodes[6].innerHTML);
        $("#birthDate").val(this.childNodes[7].innerHTML);
    });
});

表单设置如下:

<form>
  <input id="firstName" type="text"/>
  <input id="lastName" type="text"/>
  <input id="address1" type="text"/>
  <input id="address2" type="text"/>
  <input id="city" type="text"/>
  <input id="state" type="text"/>
  <input id="zip" type="text"/>
  <input id="birthDate" type="text"/>
</form>

当前,名字被放入姓氏字段中。姓氏被放入地址 1 字段中。地址1被放入状态字段,其余两个字段留空。包含数据的字段之间的字段也是空白的。

I'm trying to move data from a selected row in a table to a form in MVC. I'm using a jquery click event to retrieve the data from my table and move it to my form. The click event is working but it is moving the data to the wrong fields. Heres the click function:

$(document).ready(function () {
    $(".innerTbltr").click(function () {
        alert("Event handle.");
        //this.css("background-color", "#E8EEF4");
        $("#firstName").val(this.childNodes[0].innerHTML);
        $("#lastName").val(this.childNodes[1].innerHTML);
        $("#address1").val(this.childNodes[2].innerHTML);
        $("#address2").val(this.childNodes[3].innerHTML);
        $("#city").val(this.childNodes[4].innerHTML);
        $("#state").val(this.childNodes[5].innerHTML);
        $("#zip").val(this.childNodes[6].innerHTML);
        $("#birthDate").val(this.childNodes[7].innerHTML);
    });
});

The form is set up like this:

<form>
  <input id="firstName" type="text"/>
  <input id="lastName" type="text"/>
  <input id="address1" type="text"/>
  <input id="address2" type="text"/>
  <input id="city" type="text"/>
  <input id="state" type="text"/>
  <input id="zip" type="text"/>
  <input id="birthDate" type="text"/>
</form>

Currently the first name is put into the last name field. The last name is put into the address 1 field. The address 1 is put into the state field and the remaining two fields are left blank. As well as the fields in between the fields that have data are blank.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久光 2024-12-26 20:57:40

可能是没有加载所有 DOM 尝试将 click 事件放入 jQuery

 $(document).ready(function(){
//the click event here 
}); 

It might be that not all the DOM is loaded Try putting the click event in a jQuery

 $(document).ready(function(){
//the click event here 
}); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文