我尝试提交UL BY ORDER 的名单。我如何将它放入变量中,以便我可以发送ajax帖子?
在这种情况下,我应该得到类似List的第一个元素xzxc和第二个sdad
$('#btnSubmit').click(function (e) {
e.preventDefault();
//How do I get the List of Names from the testCaseList??
var testCaseNames =
$.ajax({
type: 'post',
url: '/create-flow/save',
data: {testCaseNames: testCaseNames},
success: (function (code) {
})
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="testCaseList" class="list-group testCaseList">
<li class="list-group-item justify-content-between" draggable="false" style="">xzxc
<div class="icons-right"><a class="action-icon" id="edit-xzxc" name="xzxc" draggable="false"><span class="fa fa-edit"></span></a><a class="action-icon" id="delete-xzxc" name="xzxc" draggable="false"><span class="fa fa-trash"></span></a></div>
</li>
<li class="list-group-item justify-content-between" draggable="false" style="">sdad
<div class="icons-right"><a class="action-icon" id="edit-sdad" name="sdad" draggable="false"><span class="fa fa-edit"></span></a><a class="action-icon" id="delete-sdad" name="sdad" draggable="false"><span class="fa fa-trash"></span></a></div>
</li>
</ul>
<button id="btnSubmit">Submit</button>
&#13;
答案 0 :(得分:1)
var testCaseNames = []
$('.action-icon:first-of-type').each(function() {
testCaseNames.push($(this).attr('name'))
})
$('#btnSubmit').click(function(e) {
e.preventDefault();
$.ajax({
type: 'post',
url: '/create-flow/save',
data: {
testCaseNames: testCaseNames
},
success: (function(code) {
})
});
});
console.log(testCaseNames);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="testCaseList" class="list-group testCaseList">
<li class="list-group-item justify-content-between" draggable="false" style="">xzxc
<div class="icons-right"><a class="action-icon" id="edit-xzxc" name="xzxc" draggable="false"><span class="fa fa-edit"></span></a><a class="action-icon" id="delete-xzxc" name="xzxc" draggable="false"><span class="fa fa-trash"></span></a></div>
</li>
<li class="list-group-item justify-content-between" draggable="false" style="">sdad
<div class="icons-right"><a class="action-icon" id="edit-sdad" name="sdad" draggable="false"><span class="fa fa-edit"></span></a><a class="action-icon" id="delete-sdad" name="sdad" draggable="false"><span class="fa fa-trash"></span></a></div>
</li>
</ul>
<button id="btnSubmit">Submit</button>
&#13;