简体   繁体   English

当我只希望onclick时显示页面加载时的警报

[英]Alert showing when the page is loaded when I only want onclick

I have a bookmarking system and when a image is bookmarked I want an alert with an image to confirm that a image is bookmarked. 我有一个书签系统,当一个图像被添加了书签时,我想要一个带有图像的警报以确认该图像被添加了书签。

I have a working alert and onclick it shows the alert. 我有一个有效的警报,并且onclick会显示警报。 However, the alert also shows when the page is loaded. 但是,警报也显示页面加载的时间。 I can't figure out how to only show the alert when the form is submitted 我不知道如何仅在提交表单时显示警报

The code: 编码:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

          <!--form which sends field information to the database-->
          <form class="form" id="form" action="" method="post" >
            <img id="enlargedSymbol" type="text" size="60" name="pathOfSymbol" src='' /> <!--large symbol where source is inserted-->
                <br />
                <!--hidden input which value is set by query where then its sent to the database-->
                <input class="inputBox" type="hidden" name="pathOfSymbol" id="pathOfSymbol" />
                      <script>
                      var querySrc = URI(window.location.href).search(true).src; //gets image source
                      //sets image source as enlarged symbol
                      $("#enlargedSymbol").prop("src", querySrc);
                      //sets path of symbol as hidden value
                      $('#pathOfSymbol').val(querySrc);
                      </script>

                        <button type="submit" name="submit" id="addToBookmarksButton" onclick="addedToBookmarks()"  >
                            <img id="addToBookmarksButton" src="img/addToBookmarks.png"  />
                        </button>


              </form>


              <script>
              $(function addedToBookmarks () {
                $("#dialog").dialog();
              });
              </script>

              <div id="dialog">
                <img src="img/addToBookmarks.png" alt="Placeholder Image" />
              </div>
<script>
     $('#addToBookmarksButton').click(function(){
          $("#dialog").dialog();
     });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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