本文介绍了我怎样才能到HTML<内部的价值; TR>目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 所以我有这样的代码。我要发送的数据,我的HTML里面输入到控制器的参数。在我的jQuery我有一条线,看起来像这样结果变种currentRow = $(本).closest(TR); ,但我不知道如何进入currentRow对象我怎么能做到这一点还是你也许知道一个更好的方式来做到这一点? $ B $内的每个输入的值b //我的html @foreach(在Model.DiscountList VAR折扣) { < TR> < TD> @ Html.TextBox(codeTextBox,discount.Code)LT; / TD> < TD><输入类型=复选框NAME =freeShippingCheckBoxID =freeShippingCheckBox检查=@ discount.FreeShipping/> < / TD> @if(discount.isTwoForThree ==真) {< TD><输入类型=电话VALUE =钽3 betala 2只读/>< / TD> } ,否则 {< TD><输入类型=数字值=@ discount.PercentOffPrice/>< / TD> } < TD><输入类型=复选框ID =activeCheckBoxNAME =activeCheckBox检查=@ discount.Active/>< / TD> < TD><输入类型=日期时间值=@ discount.CreatedDate只读/>< / TD> < TD> <输入类型=按钮值=Radera级=发发 - 删除的数据-URL =@ Url.Action(DeleteDiscountCode,打折,新{ID = discount.Id })/> <输入类型=按钮值=Uppdatera级=发发更新数据URL =@ Url.Action(UpdateDiscount,打折,新{ID = discount.Id ,})/> <输入类型=按钮值=Produkter级=发发产品/> < / TD> <输入ID =@ discount.Id.ToString()类型=隐藏值=@ discount.Id/> < / TR> } //我的jQuery $(FA-更新)。在(点击,函数(){变种currentRow = $(本).closest(TR); 的console.log(currentRow.children(#freeShippingCheckBox)VAL()); 如果(确认(你确定要编辑这个优惠码?)) { $。员额($(本)。数据(URL),功能(数据){ $阿贾克斯({网址:'@ Url.Action(DeleteUser,折扣)',型:POST,数据:freeShipping = .. ........ ???????????,成功:功能(数据){如果(数据){ } location.reload(); } }); location.reload(); 警报(已删除); })} }); //我的控制器 [HttpPost] 公共无效UpdateDiscount(INT ID,布尔freeShipping,INT percentOfPrice,布尔有效) { Service.DiscountService.UpdateDiscount(ID,freeShipping,percentOfPrice,活动); } 解决方案 我的建议是: $(函数(){$(FA-更新)。上(点击,功能(E){VAR数据= {}; VAR currentRowParams = $(本).closest(TR)找到('输入')每个(函数(指数,元素){VAR名= element.name element.name:未定义+指数数据[名] = element.value ||'';}); VAR X = JSON.stringify(数据);执行console.log(X); // / /相反,如果你想在一个传统的获取PARAMS //});}); <脚本SRC =https://code.jquery.com/jquery-1.12.4.min.js>< / SCRIPT><表> <&TBODY GT; &所述; TR> < TD> @ Html.TextBox(codeTextBox,discount.Code)LT; / TD> < TD><输入类型=复选框NAME =freeShippingCheckBoxID =freeShippingCheckBox检查=@ discount.FreeShipping/> < / TD> < TD><输入类型=电话VALUE =3钽为betala 2只读/>< / TD> < TD><输入类型=复选框ID =activeCheckBoxNAME =activeCheckBox检查=@ discount.Active/>< / TD> < TD><输入类型=日期时间值=@ discount.CreatedDate只读/>< / TD> &所述; TD> <输入类型=按钮值=Radera级=发发 - 删除的数据-URL =@ Url.Action(DeleteDiscountCode,打折,新{ID = discount.Id})/ > <输入类型=按钮值=Uppdatera级=发发更新数据URL =@ Url.Action(UpdateDiscount,打折,新{ID = discount.Id,}) /> <输入类型=按钮值=Produkter级=发发产品/> < / TD> <输入ID =@ discount.Id.ToString()类型=隐藏值=@ discount.Id/> < / TR> < / TBODY>< /表> So i have this code. I want to send the data inside of my html inputs to the controllers parameters. In my jquery i have a line that looks like thisvar currentRow = $(this).closest("tr");But i have no clue how to get into the values of each input inside the currentRow Object how can i do that or do you maybe know a better way to do this? // my html@foreach (var discount in Model.DiscountList) { <tr> <td>@Html.TextBox("codeTextBox", discount.Code) </td> <td><input type="checkbox" name="freeShippingCheckBox" id="freeShippingCheckBox" checked="@discount.FreeShipping" /> </td> @if (discount.isTwoForThree == true) { <td><input type="tel" value="Ta 3 betala för 2" readonly /></td> } else { <td><input type="number" value="@discount.PercentOffPrice"/></td> } <td><input type="checkbox" id="activeCheckBox" name="activeCheckBox" checked="@discount.Active" /></td> <td><input type="datetime" value="@discount.CreatedDate" readonly /></td> <td> <input type="button" value="Radera" class="fa fa-remove" data-url="@Url.Action("DeleteDiscountCode","Discount",new { id= discount.Id})" /> <input type="button" value="Uppdatera" class="fa fa-update" data-url="@Url.Action("UpdateDiscount","Discount",new { id= discount.Id, })" /> <input type="button" value="Produkter" class="fa fa-products" /> </td> <input id="@discount.Id.ToString()" type="hidden" value="@discount.Id" /> </tr> }//my jquery $(".fa-update").on("click", function () { var currentRow = $(this).closest("tr"); console.log(currentRow.children("#freeShippingCheckBox").val()); if (confirm("Are you sure you want to edit this discount code?")) { $.post($(this).data("url"), function (data) { $.ajax({ url: '@Url.Action("DeleteUser","Discount")', type: "POST", data: "freeShipping=..........???????????", success: function (data) { if (data) { } location.reload(); } }); location.reload(); alert("Deleted"); }) } }); //my controller [HttpPost] public void UpdateDiscount(int id, bool freeShipping, int percentOfPrice, bool active) { Service.DiscountService.UpdateDiscount(id, freeShipping, percentOfPrice, active); } 解决方案 My proposal is:$(function () { $(".fa-update").on("click", function (e) { var data = {}; var currentRowParams = $(this).closest("tr").find('input').each(function(index, element) { var name = element.name ? element.name : 'undefined' + index; data[name] = element.value || ''; }); var x = JSON.stringify(data); console.log(x); // // If instead you want the params in a traditional GET // });});<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script><table> <tbody> <tr> <td>@Html.TextBox("codeTextBox", discount.Code) </td> <td><input type="checkbox" name="freeShippingCheckBox" id="freeShippingCheckBox" checked="@discount.FreeShipping" /> </td> <td><input type="tel" value="Ta 3 betala for 2" readonly /></td> <td><input type="checkbox" id="activeCheckBox" name="activeCheckBox" checked="@discount.Active" /></td> <td><input type="datetime" value="@discount.CreatedDate" readonly /></td> <td> <input type="button" value="Radera" class="fa fa-remove" data-url="@Url.Action("DeleteDiscountCode","Discount",new { id= discount.Id})" /> <input type="button" value="Uppdatera" class="fa fa-update" data-url="@Url.Action("UpdateDiscount","Discount",new { id= discount.Id, })" /> <input type="button" value="Produkter" class="fa fa-products" /> </td> <input id="@discount.Id.ToString()" type="hidden" value="@discount.Id" /> </tr> </tbody></table> 这篇关于我怎样才能到HTML<内部的价值; TR>目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 05:51