[jQuery]セレクタhiddenのカンマ区切りのデータを配列にする方法
書式
input type="hidden" value="文字列1,文字列2″ id="xxx"
使用例
<input type="hidden" value="red,green,yellow,black" id="cft">
<input type="button" id="btnshow" value="テスト" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$("#btnshow").click(function() {
const strVal = $("#cft").val(); //hiddenの値の取得
const kk = strVal.split(",");//カンマ区切り
alert(kk); // ["red", "green", "yellow","black"] 配列
});
</script>