不太确定我在这个问题上哪里出了问题。我有一个按钮元素,单击该元素时,我希望触发下面的脚本。当我单击按钮但未获取文件时,Chrome 中似乎没有问题。
我的 .click 中是否遗漏了一些愚蠢的内容?
<script>
$( "button" ).click(function() {
$.get("testimg.php", function() {
alert("Success!");
});
});
</script>
最佳答案
你的代码看起来是正确的。您需要确保两件事:
-
testimg.php
(带有 m)文件存在于同一目录中。 <button>
脚本运行时位于 DOM 中。我建议使用$(document).ready()
事件:<script> $(document).ready(function(){ $( "button" ).click(function() { $.get("testimg.php", function() { alert("Success!"); }); }); }); </script>
关于javascript - .click 函数中的 $.get,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18368511/