gpt4 book ai didi

javascript - .click 函数中的 $.get

转载 作者:行者123 更新时间:2023-11-28 15:56:58 26 4
gpt4 key购买 nike

不太确定我在这个问题上哪里出了问题。我有一个按钮元素,单击该元素时,我希望触发下面的脚本。当我单击按钮但未获取文件时,Chrome 中似乎没有问题。

我的 .click 中是否遗漏了一些愚蠢的内容?

  <script>
$( "button" ).click(function() {
$.get("testimg.php", function() {
alert("Success!");
});
});
</script>

最佳答案

你的代码看起来是正确的。您需要确保两件事:

  1. testimg.php (带有 m)文件存在于同一目录中。
  2. <button>脚本运行时位于 DOM 中。我建议使用$(document).ready()事件:

    <script>
    $(document).ready(function(){
    $( "button" ).click(function() {
    $.get("testimg.php", function() {
    alert("Success!");
    });
    });
    });
    </script>

Working jsFiddle

关于javascript - .click 函数中的 $.get,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18368511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com