Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 选中复选框时如何获取模式?_Php_Jquery_Checkbox - Fatal编程技术网

Php 选中复选框时如何获取模式?

Php 选中复选框时如何获取模式?,php,jquery,checkbox,Php,Jquery,Checkbox,这是我的密码 ex1.php <body> <form> <label> <input type="checkbox" value="LH" name="name">LH</label> <label> <input type="checkbox" value="LJ" name="name">LJ</label> <label> <input

这是我的密码

ex1.php

<body>

<form>

  <label>
    <input type="checkbox" value="LH" name="name">LH</label>
  <label>
    <input type="checkbox" value="LJ" name="name">LJ</label>
  <label>
    <input type="checkbox" value="LL" name="name">LL</label>
  <label>
    <input type="checkbox" value="FA" name="name">FA</label>
  <label>
    <input type="checkbox" value="FB" name="name">FB</label>
  <label>
    <input type="checkbox" value="FU" name="name">FU</label>
</form>

<!--modal-->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <?php

        $test = $_POST['test'];

        $servername = "localhost";
        $username = "root";
        $password = "";


// Create connection
        $conn = mysqli_connect($servername, $username, $password);


// Check connection
        if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
        }
        echo "Connected successfully";

        mysqli_connect_db("db",$conn);

        $sql = "SELECT Subcat FROM subcat where CatId=".$test." ";
        $res = mysqli_query($conn,$sql);
        while($row = mysqli_fetch_assoc($res)){
        echo "<input type='checkbox' name='category[]' value='".$row['Subcat']."'>"
        .$row['Subcat'];
        echo "<br>";   
}
        ?>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>


</body>
<body>

<form>

  <label>
    <input type="checkbox" value="LH" name="name">LH</label>
  <label>
    <input type="checkbox" value="LJ" name="name">LJ</label>
  <label>
    <input type="checkbox" value="LL" name="name">LL</label>
  <label>
    <input type="checkbox" value="FA" name="name">FA</label>
  <label>
    <input type="checkbox" value="FB" name="name">FB</label>
  <label>
    <input type="checkbox" value="FU" name="name">FU</label>
</form>

<!--modal-->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

</body>
<?php

            $test = $_POST['test'];

            $servername = "localhost";
            $username = "root";
            $password = "";


    // Create connection
            $conn = mysqli_connect($servername, $username, $password);


    // Check connection
            if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
            }
            echo "Connected successfully";

            mysqli_connect_db("db",$conn);

            $sql = "SELECT Subcat FROM subcat where CatId=".$test." ";
            $res = mysqli_query($conn,$sql);
            while($row = mysqli_fetch_assoc($res)){
            echo "<input type='checkbox' name='category[]' value='".$row['Subcat']."'>"
            .$row['Subcat'];
            echo "<br>";   
    }
?>
我想在这里做的如下

我在表格中有一个复选框列表。当我点击复选框时,会出现一个模式,其中包含来自数据库的相应数据。我是
Jquery
的初学者。我的代码不起作用。我到处都能找到解决办法。但我不能

谁能帮我一下吗?

你可以用

$('#myModal').modal('show')
打开id为myModal的模型的步骤

$('#myModal').modal('hide')
隐藏模态

从post请求加载数据后,使用
success:function()
中的值填充模型,并使用
$('#myModal').modal('show')
向用户显示模型,您可以使用

$('#myModal').modal('show')
打开id为myModal的模型的步骤

$('#myModal').modal('hide')
隐藏模态


从post请求加载数据后,使用
success:function()
中的值填充模型,并使用
$(“#myModal”).modal('show')
向用户显示模型

如果您不熟悉JSON/api,请执行以下操作:

ex1.php

<body>

<form>

  <label>
    <input type="checkbox" value="LH" name="name">LH</label>
  <label>
    <input type="checkbox" value="LJ" name="name">LJ</label>
  <label>
    <input type="checkbox" value="LL" name="name">LL</label>
  <label>
    <input type="checkbox" value="FA" name="name">FA</label>
  <label>
    <input type="checkbox" value="FB" name="name">FB</label>
  <label>
    <input type="checkbox" value="FU" name="name">FU</label>
</form>

<!--modal-->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <?php

        $test = $_POST['test'];

        $servername = "localhost";
        $username = "root";
        $password = "";


// Create connection
        $conn = mysqli_connect($servername, $username, $password);


// Check connection
        if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
        }
        echo "Connected successfully";

        mysqli_connect_db("db",$conn);

        $sql = "SELECT Subcat FROM subcat where CatId=".$test." ";
        $res = mysqli_query($conn,$sql);
        while($row = mysqli_fetch_assoc($res)){
        echo "<input type='checkbox' name='category[]' value='".$row['Subcat']."'>"
        .$row['Subcat'];
        echo "<br>";   
}
        ?>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>


</body>
<body>

<form>

  <label>
    <input type="checkbox" value="LH" name="name">LH</label>
  <label>
    <input type="checkbox" value="LJ" name="name">LJ</label>
  <label>
    <input type="checkbox" value="LL" name="name">LL</label>
  <label>
    <input type="checkbox" value="FA" name="name">FA</label>
  <label>
    <input type="checkbox" value="FB" name="name">FB</label>
  <label>
    <input type="checkbox" value="FU" name="name">FU</label>
</form>

<!--modal-->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

</body>
<?php

            $test = $_POST['test'];

            $servername = "localhost";
            $username = "root";
            $password = "";


    // Create connection
            $conn = mysqli_connect($servername, $username, $password);


    // Check connection
            if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
            }
            echo "Connected successfully";

            mysqli_connect_db("db",$conn);

            $sql = "SELECT Subcat FROM subcat where CatId=".$test." ";
            $res = mysqli_query($conn,$sql);
            while($row = mysqli_fetch_assoc($res)){
            echo "<input type='checkbox' name='category[]' value='".$row['Subcat']."'>"
            .$row['Subcat'];
            echo "<br>";   
    }
?>

如果您不熟悉JSON/api,请执行以下操作:

ex1.php

<body>

<form>

  <label>
    <input type="checkbox" value="LH" name="name">LH</label>
  <label>
    <input type="checkbox" value="LJ" name="name">LJ</label>
  <label>
    <input type="checkbox" value="LL" name="name">LL</label>
  <label>
    <input type="checkbox" value="FA" name="name">FA</label>
  <label>
    <input type="checkbox" value="FB" name="name">FB</label>
  <label>
    <input type="checkbox" value="FU" name="name">FU</label>
</form>

<!--modal-->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <?php

        $test = $_POST['test'];

        $servername = "localhost";
        $username = "root";
        $password = "";


// Create connection
        $conn = mysqli_connect($servername, $username, $password);


// Check connection
        if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
        }
        echo "Connected successfully";

        mysqli_connect_db("db",$conn);

        $sql = "SELECT Subcat FROM subcat where CatId=".$test." ";
        $res = mysqli_query($conn,$sql);
        while($row = mysqli_fetch_assoc($res)){
        echo "<input type='checkbox' name='category[]' value='".$row['Subcat']."'>"
        .$row['Subcat'];
        echo "<br>";   
}
        ?>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>


</body>
<body>

<form>

  <label>
    <input type="checkbox" value="LH" name="name">LH</label>
  <label>
    <input type="checkbox" value="LJ" name="name">LJ</label>
  <label>
    <input type="checkbox" value="LL" name="name">LL</label>
  <label>
    <input type="checkbox" value="FA" name="name">FA</label>
  <label>
    <input type="checkbox" value="FB" name="name">FB</label>
  <label>
    <input type="checkbox" value="FU" name="name">FU</label>
</form>

<!--modal-->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

</body>
<?php

            $test = $_POST['test'];

            $servername = "localhost";
            $username = "root";
            $password = "";


    // Create connection
            $conn = mysqli_connect($servername, $username, $password);


    // Check connection
            if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
            }
            echo "Connected successfully";

            mysqli_connect_db("db",$conn);

            $sql = "SELECT Subcat FROM subcat where CatId=".$test." ";
            $res = mysqli_query($conn,$sql);
            while($row = mysqli_fetch_assoc($res)){
            echo "<input type='checkbox' name='category[]' value='".$row['Subcat']."'>"
            .$row['Subcat'];
            echo "<br>";   
    }
?>

使用
$(“输入[type=checkbox]”)而不是
$(“:checkbox”)
。还需要放置模态来分隔php文件。您可以通过两种方式来完成此操作,如:)1)将模型打开类名指定给复选框(表示当您单击按钮或模型弹出窗口将打开的任何链接时,模型弹出窗口会弹出,因此将该值放入复选框)2)在ajax中成功触发单击function@NikolayKrasnov ,为什么我应该把模态放在单独的php文件中?你能解释一下吗?用
$(“输入[type=checkbox]”)代替
$(“:checkbox”)
。还需要放置模态来分隔php文件。您可以通过两种方式来完成此操作,如:)1)将模型打开类名指定给复选框(表示当您单击按钮或模型弹出窗口将打开的任何链接时,模型弹出窗口会弹出,因此将该值放入复选框)2)在ajax中成功触发单击function@NikolayKrasnov ,为什么我应该把模态放在单独的php文件中?你能解释一下吗?