本文介绍了如何使用更改事件下拉列表中的选定值更新输入元素属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用输入元素中的下拉列表中的选定值更新data-reason属性?
< table class ='reorderTablerow'>
< tbody>
< tr>
< td>
< input data-item ='item A'data-itemid ='001'data-reason =''class ='quanityborderinput'type = text />
< / td>
< td>
< select>
< option>选择原因< / option>
< option>缺货< / option>
< option>损坏的商品< / option>
< / select>
< / td>
< / tr>
< tr>
< td>
< input data-item ='item B'Data-itemid ='002'data-reason =''class ='quanityborderinput'type = text />
< / td>
< td>
< select>
< option>选择原因< / option>
< option>缺货< / option>
< option>损坏的商品< / option>
< / select>
< / td>
< / tr>
< / tbody>
< / table>
我的尝试:
到目前为止我的代码jquery代码是
部分jQuery
var orderformcontainer = $ (这个).parent()的父();
var timestamp = moment();
var OrderFormType = $(this).attr(data-orderformtype);
var quanityinputboxes = orderformcontainer.parent()。find(tbody .quanityborderinput);
var items = quanityinputboxes.filter(function(index){
return $(this).val()。length> 0;
});
var orderitems = [];
items.each(function(index,element){
var itemid = $(element).attr(data-itemid);
var quantity = $(element).val( );
var name = $(element).attr(data-itemname);
});
解决方案
How do i update data-reason attribute with selected value from drop down in my input element? <table class='reorderTablerow'> <tbody> <tr> <td> <input data-item='item A' data-itemid='001' data-reason='' class='quanityborderinput' type=text/> </td> <td> <select> <option>Select reason</option> <option>Out of stock</option> <option>Damaged item</option> </select> </td> </tr> <tr> <td> <input data-item='item B' data-itemid='002' data-reason='' class='quanityborderinput' type=text/> </td> <td> <select> <option>Select reason</option> <option>Out of stock</option> <option>Damaged item</option> </select> </td> </tr> </tbody> </table>
What I have tried:
so far my code jquery code is
Part of jQuery var orderformcontainer = $(this).parent().parent(); var timestamp = moment(); var OrderFormType = $(this).attr("data-orderformtype"); var quanityinputboxes=orderformcontainer.parent().find("tbody .quanityborderinput"); var items = quanityinputboxes.filter(function (index) { return $(this).val().length > 0; }); var orderitems = []; items.each(function (index, element) { var itemid = $(element).attr("data-itemid"); var quantity = $(element).val(); var name = $(element).attr("data-itemname"); });
解决方案
这篇关于如何使用更改事件下拉列表中的选定值更新输入元素属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!