javascript - 为 jQuery 位置变量获取未定义

标签 javascript jquery html css

$("#capture").click(
    function(event) {
        var photoCoords = $("#doge1").position();
    })

在用户单击 ID 为 #capture 的拍摄按钮后,我使用上面的代码获取照片的坐标。该图像的 ID 为 #doge1。

当我在控制台中输入 var photoCoords 时,我得到了未定义的返回值。

最佳答案

你应该编写如下代码:

var photoCoords;    
$("#capture").click(function(event) {
    photoCoords = $("#doge1").position();
});

关于javascript - 为 jQuery 位置变量获取未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21843277/

相关文章:

javascript - 来自给定选择器的 nodeList 的 Jasmine 测试事件监听器函数

javascript - npm FontAwesome Angular 4 编译错误

jquery - 在 jQuery 中选择编号元素范围

jquery - 将值重复输出到表中

jquery - 向后滚动时回到旧样式

javascript - 提示安装语言包

angularjs - 从 angularJS Controller 关闭当前选项卡

javascript - 检查输入值长度

html - 从 Perl 和 Catalyst 中的用户输入中删除 HTML

javascript - 检索数组JS中的所有对象