gpt4 book ai didi

javascript - 如何获取多个选择框值并插入字符串数组

转载 作者:行者123 更新时间:2023-11-30 12:15:37 24 4
gpt4 key购买 nike

我正在使用多选框。我需要能够添加和删除值并创建逗号分隔的字符串数组。

我做了一个plunker。 plunker

 var msaskArray = [];
$scope.$watch("MSASK", function (newValue, oldValue) {
if (newValue != null) {
msaskArray.push(newValue)
}
console.log(JSON.stringify(msaskArray))
});

我附上了我目前得到的结果的截图。 pic

我需要的结果应该是这样的

["9,14,18"]

最佳答案

您错过了 plunkr 中的 multiple 属性,该属性允许您选择多个选项。

根本不需要将 $watch 放在 MASK 变量上。您可以在需要时轻松使用 $scope.MASK。还可以使用 ng-change 指令在选择框的更改事件上获取射击范围功能。

标记

<select ng-options="m.MSASK as m.Market_Name for m in markets" 
ng-model="MSASK" multiple></select>

Plunkr Here

关于javascript - 如何获取多个选择框值并插入字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32510699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com