[jQuery]セレクタhiddenのカンマ区切りのデータを配列にする方法

2021年8月3日

書式
input type="hidden" value="文字列1,文字列2″ id="xxx"
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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>
<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>

 

Oracle

Posted by arkgame