javascript - 当我只想 onclick 时显示页面加载时的警报

标签 javascript jquery html onclick

我有一个书签系统,当图像被添加书签时,我想要一个带有图像的警报来确认图像被添加书签。

我有一个工作警报,单击它会显示该警报。但是,该警报还会在页面加载时显示。我不知道如何仅在提交表单时显示警报

代码:

<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>

关于javascript - 当我只想 onclick 时显示页面加载时的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35632354/

相关文章:

php - 包含数据的可点击 HTML 表格能够在点击时显示更多数据

javascript - 将数组元素替换为 id 标签

javascript - 如何修复这个错误?

javascript - 克隆每个,附加到每个

javascript - 正则表达式 JS 模式 : 0. 000 - 1.600

jquery - 使用 jQuery 从数组中的项目中剥离 HTML 代码

jQuery 验证(日期范围)

css - Mailchimp 模板的 HTML 中的怪癖/错误

CSS/HTML : Designing with pixels for multi DPI devices? 保持相同尺寸?

javascript - 为什么表格内的文本框不会触发 onkeypress 事件?