将javascript变量传递给模式弹出窗口

时间:2018-11-19 09:30:16

标签: javascript jquery ajax bootstrap-4

在点击.change_Nodes类时,我会获得“ id”的值,在确认框(是),我需要将JavaScript值传递给名为#custom_script_modal的模式弹出窗口。

$(document).on("click",".Change_Nodes",function(){

  cmd_name = $(this).attr("id");

  if(confirm("Sure to Update \""+cmd_name+"\" Command Executable Nodes?"))
  {
    $('#custom_script_modal').modal('show');
  }
  else
  { return false; }
}
); //update: removed extra curly brace
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="modal fade" id="custom_script_modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title text-center" id="custom_script_data_modal">Update Custom Script Executable Nodes</h4>
            </div>
            <div class="modal-body">
                <form method="POST" id="custom_script_modal">
                    <label class="control-label col-sm-4" for="cmd">List of Nodes</label>
                    <div class="col-sm-8 tab-pan fade in active">
                        <select size="3" name="popup_hostlist[]" id="popup_hostlist" class="dis_tab" multiple>
                            <?php    
                                //-----------Database                                                                           echo "<option value='". $row['NodeName'] . "'>". $row['NodeName'] ."</option>";           
                            ?>
                        </select>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-info form-control">Update</button>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

据我所知-您想更改“ cmd_name”变量的动态值,并在UI上进行任何特定选择时进行更改,然后对这些操作重新使用相同的模式片段。

在可操作元素上为“ cmd_name”设置数据属性,并在提示用户时访问相同的变量。

查看以下JSFiddle,让我知道您的情况是否有帮助:

(https://jsfiddle.net/sunnysharma/xpvt214o/950935/)

enter image description here

enter image description here

enter image description here

enter image description here