我不知道为什么 $getScript 不能在 Firefox 浏览器的点击功能中工作,但可以在其他浏览器上工作。 click 函数之外的相同代码也适用于 Firefox。有人可以解释一下问题是什么吗?
<script type="text/javascript">
var page = "";
page = window.location.href;
jQuery(document).ready(function($){
$( "#socialemail" ).click(function() {
$.getScript('/social-media.php?email&' + page);
window.location.href="mailto:?subject=text here Systems&body="+escape(window.location.href);
});
});
</script>
最佳答案
由于 $.getScript()
是异步的,并且我希望您想要等待它的结果,因此您应该执行以下 window.location.href
属性更改在传递给 $.getScript()
的回调函数中。类似的东西
var page = "";
page = window.location.href;
jQuery(document).ready(function($){
$( "#socialemail" ).click(function(e) {
// prevent the default action of clicking on whatever element
// with id 'socialemail' is
e.preventDefault();
$.getScript('/social-media.php?email&' + page, function () {
// run this after the script has been fetched
window.location.href="mailto:?subject=text here Systems&body="+encodeURIComponent(window.location.href);
});
});
});
关于javascript - $.getScript 在点击函数中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23397710/