Jqueryで選択されたチェックボックスリスト値を取得する方法

フロントエンド 2021-09-28 21:03:17 0 4,045

この投稿では、jqueryのチェックボックスリストから選択されたチェックボックス値を取得する方法を説明します。ここでは、チェックボックスjqueryの例を使用して、複数の選択されたチェックボックス値を取得します。その時点でテーブル行に複数のチェックボックスがある場合は、配列のチェックボックス値を取得します。 jqueryの文字列。

この例では、jqueryコード、htmlチェックボックス、bootstrape cdn、jqueryリンクを追加したので、jqueryで複数のチェックボックス値を取得する方法を見てみましょう。

<html>
<head>
	<title>Get selected checkbox value from checkboxlist using jquery - itdot.cn</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>

    <div class="container" style="border:1px solid gray; margin-top: 20px;">
        <h3 class="text-center">Get selected checkbox value from checkboxlist using jquery - itdot.cn</h3>
        <div style="margin-left: 210px;">
        <input type="checkbox" id="id1" value="PHP"/> <label>PHP</label> <br>
        <input type="checkbox" id="id2" value="jQuery"/> <label>jQuery</label> <br>
        <input type="checkbox" id="id3" value="CSS"/> <label>CSS</label> <br>
        <input type="checkbox" id="id4" value="Bootstrap"/> <label>Bootstrap</label> <br>
        <input type="checkbox" id="id5" value="Laravel"/> <label>Laravel</label> <br><br>
        <input type="button" id="btn" value="Submit" class="btn btn-primary" style="margin-bottom: 20px;" />
        </div>
    </div>
</body>
<script type="text/javascript">
    $(function () {
        $("#btn").click(function () {
            var selected = new Array();
            $("input[type=checkbox]:checked").each(function () {
                selected.push(this.value);
            });
            if (selected.length > 0) {
                alert("Selected items: " + selected.join(","));
            }
        });
    });
</script>
</html>

Jqueryで選択されたチェックボックスリスト値を取得する方法-ITdot

#Jquery#


あなたのコメント

すでに 0 記事の回答
暑さランキング
最新の回答