[英]Value from comma separated select option values and append the second value to a other select option
i'm struggling with a question, how i can get the value from comma separated select option value and append the second value to a other select option? 我在想一个问题,我如何从逗号分隔的选择选项值中获取值并将第二个值附加到另一个选择选项中? My html looks
我的HTML外观
<select id="firstSelecter_ID1">
<option value"first value, second value, third value">option1</option>
<option value"first value, second value, third value">option2</option>
<option value"first value, second value, third value">option3</option>
<option value"first value, second value, third value">option4</option>
</select>
<select id="secondSelecter_ID2">
<option value"second value">option1-a</option>
<option value"second value">option2-a</option>
<option value"second value">option3-a</option>
<option value"second value">option4-a</option>
</select>
var entry6 = $('#Id_6')
entry6.on('change', 'select#firstSelecter_ID1', function (e) {
...
option value ,second .append() to #secondSelecter_ID2 as new option value =""
...
}
Many thanks if somebody can give me the idea and I hope I have asked the question right and understandable Regards Maty 非常感谢有人能给我这个主意,我希望我问的这个问题是对的,可以理解。
Try something like 尝试类似
$('#select_1 option').each(function(){
var secondVal = this.value.split(',')[1].trim(),
$opt = $('<option>').val(secondVal).text($(this).text());
$('#select_2').append($opt);
});
Ok, i got it to work how i need it... 好吧,我知道如何工作了……
entry1.on('change', 'select#actiontypeSelect', function (e) {
$("select#secondSelecter_ID2 option:eq(1)").remove();
$("select#secondSelecter_ID2 option:last").remove();
$('select#actiontypeSelect').each(function () {
var value1 = $('select#actiontypeSelect').find("option:selected").val();
var secondVal = value1.split(',')[1].trim(),
$opt = $('<option>').val(secondVal).text('Exclusive Equipment');
$('#secondSelecter_ID2').append($opt);
console.log(value1);
});
$("select#secondSelecter_ID2").append('<option value="0.00">Inclusive Equipment</option>');
e.preventDefault();
});
This gives me from the selected option the second value and append as a new option with the value to other select box. 这为我提供了来自所选选项的第二个值,并将新添加的值附加到其他选择框。
Special thanks to @charlietfl he gives me the right way. 特别感谢@charlietfl,他给了我正确的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.