1 回答
TA贡献1830条经验 获得超3个赞
我已经创建了一个演示示例(通过添加您的json响应数据表单 db.php)来说明您所说的内容。您可以存储data-id点击发送按钮。
运行下面的代码片段并选择选项并单击发送以查看数组uids将具有data-id所选选项的。
//Store in array()
var uids = [];
//Select option function
$(document).on("change", ".drop", function() {
//Find option selected
var data = $(this).find("option:selected").attr('data-id')
//Push selected data-id
uids.push(data)
//Enable button on selection
$('#seedoc').prop('disabled', false)
})
//Send
function send() {
console.log(uids)
}
//response
var res = {
"users": ["<p style='margin:0px;display:none;'data-id='755'>amilham</p>",
"<p style='margin:0px;display:none;'data-id='706'>a_sarabi</p>"
]
}
function getEmails() {
res.users.forEach(function(option) {
$('.drop').append('<option data-id=' + $(option).attr('data-id') + '>' + option + '</option>');
});
}
function addOne() {
$('#container').append("<div class='form-group' style='display:flex'><select class='drop form-control' name='option' id='option'> <option value='' disabled selected>Select your option</option> </select>");
getEmails();
}
getEmails();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container" class=""></div>
<button id="seedoc" style="float: right; margin-right: 10px;" onclick="addOne();" disabled>Add one </button>
<div class='form-group' style='display:flex'>
<select class='drop form-control' name='option' id='option'>
<option value='' disabled selected>Select your option</option>
</select>
<button class="btn btn-primary shrBtn" style="float:left;" onclick="send()">Send</button>
</div>
添加回答
举报