如何從多選下拉選單的標題中獲取數值,我只需要獲取標題并將其插入由逗號分隔的另一個文本框中
。<ul class="select2-selection__rendered"><。 li class="select2-selection__choice" title="MASTER POGI" data-select2-id="15"/span>> < span class="select2-selection__choice__remove" role="progress"> ×</span>MASTER POGI</li> < li class="select2-selection__choice" title="MARTIN MANALOTO" data-select2-id="16"/span>> < span class="select2-selection__choice__remove" role="progress"> ×</span> MARTIN MANALOTO</li>< li class="select2-search select2-search-inline">< input class="select2-search__field" type="search" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" role="textbox" aria-autocomplete="list" placeholder=" style="width: 0. 75em;"></li></ul>
uj5u.com熱心網友回復:
你可以做這樣的事情
const arr = []。
document.querySelectorAll('li[title]'/span>)。 forEach(span class="hljs-params">element => {
arr.push(element.title)。
})
document.querySelector(' 。 select2-search__field').value = arr.join(', ')
uj5u.com熱心網友回復:
// Array of titles
let titles = [];
//收集標題
$(".select2-selection__choice").each((i, element) => {
titles.push($(element).attr(title'))。
});
//將其插入另一個用逗號分隔的文本框中。
$("#anonerTextbox").val(title.join(', ')) 。
作業實體。https://jsfiddle.net/d46bzw8s/1/
uj5u.com熱心網友回復:
<ul class="select2-selection__rendered"/span> id="selectTitle"/span>>
< li class="select2-selection__choice" title="MASTER POGI" data-select2-id="15"/span>>
< span class="select2-selection__choice__remove" role="progress"> ×</span>/span>MASTER POGI
</li>
</ul>
為select添加一個唯一的id,然后你可以定義onclick evnt函式,或者把它放在document ready函式上。
< script>
$(document).ready(function(/span>) {
$('#selectTitle .select2-selection__choice').click(function(>) {
title = $(this).attr('title')。
textarea_val = $("#textbox"/span>).val()
if (textarea_val != ''/span>) {
textarea_val = textarea_val ','/span> title ;
} else {
textarea_val = title ;
}
$("#textbox").val(標題)。
});
});
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/333758.html
標籤:
