javascript - 从弹出模式中选择单选值,无需重新加载页面

标签 javascript php jquery ajax

我有一个模式弹出窗口。如果单击该模式,则会打开一个弹出窗口并出现单选按钮。如果单击任何单选按钮并提交该弹出窗口,则选定的单选值应显示在段落标记中,而无需重新加载页面。

我有代码,但它不起作用。

我的模式按钮是:(index.php)

<div id="dvPassport1">
            <div class="col-md-6">
        <label>Select Loyalty Membership</label><br>
        <a class="showModal btn btn-primary btn-xs" data-queryid="q11" > View Loyalty Membership</a>
        </div>
        <div class="col-md-6">
        <label>Employee IDs</label>
        <p></p>
        </div>
         </div>

现在,如果单击“查看忠诚度成员(member)资格”按钮,则会打开一个弹出窗口(代码如下)(index.php):

<!-- popup modal-->
<div id="id01" class="modal">

 <form class="modal-content animate" action="" method="post" autocomplete="off">
<div class="imgcontainer">
  <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>

</div>

<div class="container">
     <div class="modalContent"></div>

</div>
</form>
</div>
<script>
// Get the modal1
jQuery(document).ready(function($){
var modal = $("#id01");
$("a.showModal").on("click", function(){
    modal.fadeIn();
    var id = $(this).attr("data-queryid");
    var modalServiceUrl = "showstate.php?queryid7="+id;
    modal.find(".modalContent").load(modalServiceUrl);
});
});
// When the user clicks anywhere outside of the modal1, close it
window.onclick = function(event) {

if (event.target == modal1) {
    modal1.style.display = "none";
}
}
</script>
<!-- end popup modal -->

脚本是(index.php)

<script>
$(document).ready(function(){
$('#btnGetValue').click(function() {
    var selValue = $('input[name=rbnNumber]:checked').val(); 
    $('p').html('<br/>Selected Radio Button Value is : <b>' + selValue + '</b>');
});
});

</script>

以上所有代码都在index.php

showstate.php 是:

<?php
if(isset($_GET['queryid7'])){

$queryid7 = $_GET['queryid7'];
echo"<div align='center' style='height:660px; overflow:auto;'  class='w3l-table-info'><h2>Select your Loyalty membership</h2><table id='table'><thead>
    <tr><th>&nbsp;</th>";
 $query12=mysql_query("select * from loyalty_group ORDER BY id") or die (mysql_error());
while($row12=mysql_fetch_array($query12))
        {
            $group_name1=$row12['group_name'];
            $id11=$row12['id'];
echo"<th><input type='radio' id='rbnNumber' name='rbnNumber' value='$id11'/>".$group_name1.'</th>';

        }
echo"<th>&nbsp;</th></tr></thead><tbody>";
echo"</tbody>
<tr><td>&nbsp;</td><td><br><button type='submit' id='btnGetValue' class='btn btn-primary'>Select</button></td></tr>

 </table></div>";
 ?>

现在,如果任何单选按钮选择单击“选择”按钮,则 value='$id11' 的值应显示在 段落标记(p)(index.php) 中无需重新加载页面(index.php) 并且弹出窗口应该关闭。

最佳答案

您的<button type="submit"></button>发送表单并重新加载当前页面,因为 <form action=..没有指定。你想在这里使用的是 <button type="button"></button>

关于javascript - 从弹出模式中选择单选值,无需重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48249974/

相关文章:

javascript - 谷歌浏览器 : How to determine which window has generated WebRequest?

javascript - RequireJS 中的绝对库依赖

php - 在 Laravel Transformers 上使用中间件调用 null 上的成员函数 createData()

javascript - 仅选择 jQuery 集合中的一个元素

jquery - Twitter 需要 Bootstrap 轮播优化解决方案

jquery - 为什么我的 jQueryUI 对话框不会关闭?

javascript - 如何使用 ng-animate 在表格行中对指定的表格数据进行动画处理?

javascript - 如何为网格中的字段调用 javascript 函数

php - Laravel - 是否可以从 Redis 队列中删除特定作业?

php - MySQL tinyint 比较器返回空集