简体   繁体   中英

Calling a function on click of OK button in a pop up in the Javascript

I have a function in Javascript that displays a pop-up. I am doing this in a Sitecore based MVC project and hence I can not do the events in the normal way but following the practice that is followed in project.

if (isWarning) {
        $('#warning').modal('show');
        $("#WarningDisplay").val("true");
    }

Now the modal is shown without any problem and the modal has a OK button only (Only one button). Clicking on OK should call this function below.

function DialogOkClick() {
    $('#warning').modal('close');
    $('#CalButton').click();
}

Basically, what I intend to do in this function is, close the pop up and trigger the click even of home page.

How to call this function on click of OK in the pop up which is displayed as a result of first function? Its a modal pop up.

EDIT:

We use InfoDialogViewModel in the cshtml file for defining the warning dialog and its contents.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<script>
 $(document).ready(function () {


$('#warning').modal({ backdrop: 'static', keyboard: false })
            .one('click', '#btnOK', function (e) {
                $('#CalButton').trigger('click');

            });


$('#CalButton').click(function () {

    alert('function');
});
    });


</script>



<body>

    <button id="CalButton">Add</button>
<div class="container">

  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="warning" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <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">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal" id="btnOK">OK</button>
        </div>
      </div>

    </div>
  </div>

</div>

</body>
</html>

尝试这个:

window.parent.document.getelementbyid("CalButton")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM