Jquery 如何在更改dropdownlist时获取动态表行
嗨,当我选择下拉列表时,我正在尝试获取表格行。这是我的密码,请帮帮我。你好,鲁比对不起,首先我对这个问题理解错了。。试试这个Jquery 如何在更改dropdownlist时获取动态表行,jquery,Jquery,嗨,当我选择下拉列表时,我正在尝试获取表格行。这是我的密码,请帮帮我。你好,鲁比对不起,首先我对这个问题理解错了。。试试这个 $.ajax({ type: 'GET', url: "/HostingProject/SIPAdminCustServlet", data: {ActionType:"1",userID:userID }, success:function(responseJson){ var tbody = $("#Account")
$.ajax({
type: 'GET',
url: "/HostingProject/SIPAdminCustServlet",
data: {ActionType:"1",userID:userID },
success:function(responseJson){
var tbody = $("#Account");
alert("JSonResponse: "+responseJson);
$.each(responseJson, function(index, account) { // Iterate over the JSON array.
var value = ATYpeMap[account.AccountTypeID];
$('<tr>').appendTo(tbody) // Create HTML <tr> element, set its text content with currently iterated item and append it to the <table>.
.append($('<td>').text(account.AccountNumber)) // Create HTML <td> element, set its text content with id of currently iterated account and append it to the <tr>.
.append($('<td>').text(value)) // Create HTML <td> element, set its text content with name of currently iterated account and append it to the <tr>.
.append($('<td>').text(account.AccountStatus))
.append ($('<select id="Accountchange"+r+ onchange="dropDownOnChange(this)"><option value="Valid">Valid</option><option value="Invalid">Invalid</option></select>'))
});
}
});
};
var selectedValue;
function dropDownOnChange(e){
selectedValue=e.options[e.selectedIndex].value;
alert("selectedValue:" + selectedValue);
}
您需要在函数中添加行dropDownOnChange@Priyank,我正在尝试在函数dropDownOnChange中添加行,但我不知道如何在更改下拉列表时获取AccountNumber。谢谢。您好,RubyI已经尝试了这个'var parent=$this.parentstr;alertparent+parent.val;'但上面写着undefined.@Priyank。谢谢你的帮助。我试图实现你的代码,但上面写着“Uncaught SyntaxError:意外标识符”。实际上,我需要从同一行中获取下拉值+AccountNo,而且我还可以获取多行。非常感谢你的帮助。//试试这个。previoud代码var currentRow=$e.closesttr中存在一些键入错误;var AccountNo=$td:eq0,$currentRow.text@普里扬克,非常感谢你。它起作用了。再次感谢。你好,鲁比
var currentRow= $(e).closest("tr");
var AccountNo= $("td:eq(0)",$(currentRow)).text();
//You can change the index eq(0) to eq(1) and so on to get the next cells.
//Alternatively you can give an attribute to column while adding like
//.append($('<td>').text(account.AccountNumber).attr("colType='AcNo'"))
//And get Account No Like var AccountNo= $("td[colType='AcNo']",$(tr)).text();
//Usign the alternative approch will make your code independent of index. which is good for //maintainability and readability