Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery代码正在JSFIDLE上运行,但在我的web应用程序中没有_Javascript_Jquery_Html_Typeerror - Fatal编程技术网

Javascript jQuery代码正在JSFIDLE上运行,但在我的web应用程序中没有

Javascript jQuery代码正在JSFIDLE上运行,但在我的web应用程序中没有,javascript,jquery,html,typeerror,Javascript,Jquery,Html,Typeerror,我在使用jQuery时遇到了一个奇怪的问题。我在页面上有一组按钮,当长时间单击时,意味着在按钮位置弹出一个输入框 HTML <div class="popupView" id="recoveryView"> <button class="intervalBtn" type="button" name="recovery0" id="recovery0">00:30</button> <button class="intervalBtn"

我在使用jQuery时遇到了一个奇怪的问题。我在页面上有一组按钮,当长时间单击时,意味着在按钮位置弹出一个输入框

HTML

<div class="popupView" id="recoveryView">
    <button class="intervalBtn" type="button" name="recovery0" id="recovery0">00:30</button>
    <button class="intervalBtn" type="button" name="recovery6" id="recovery6">00:35</button>
    <button class="intervalBtn" type="button" name="recovery1" id="recovery1">02:00</button>
    <button class="intervalBtn" type="button" name="recovery7" id="recovery7">03:00</button>
    <button class="intervalBtn" type="button" name="recovery2" id="recovery2">04:00</button>
    <button class="intervalBtn" type="button" name="recovery8" id="recovery8">05:00</button>
</div>
<input id="edit_interval" type="text" />
JavaScript

$(".intervalBtn").click(function () {
    $(".intervalBtn").removeClass("selected");
    $(this).addClass('selected');
}).mouseup(function () {
    clearTimeout(pressTimer);
    return false;
}).mousedown(function () {
    // Set timeout
    pressTimer = window.setTimeout(function () {
        console.log("interval button long click");

        $("#edit_interval").css("display", "block").css("left", $(this).position().left).css("top", $(this).position().top);
    }, 1000)
    return false;
});
如果在小提琴中运行,唯一的问题是框的位置(我是否得到了错误的左侧和顶部位置?)

TypeError:“undefined”不是“in”(计算“t in e”)的有效参数

jQuery.min.js:5

这是一个分为两部分的问题(重点是第1部分):

  • 为什么会出现此错误(是错误吗?),如何修复它?
  • 如何将输入框设置到正确的位置?
  • 编辑

    $(".intervalBtn").click(function () {
        $(".intervalBtn").removeClass("selected");
        $(this).addClass('selected');
    }).mouseup(function () {
        clearTimeout(pressTimer);
        return false;
    }).mousedown(function () {
        // Set timeout
        pressTimer = window.setTimeout(function () {
            console.log("interval button long click");
    
            $("#edit_interval").css("display", "block").css("left", $(this).position().left).css("top", $(this).position().top);
        }, 1000)
        return false;
    });
    
    正如评论中所建议的,我将
    jquery.min.js
    替换为
    jquery.js
    ,并且有一个更容易调试的错误:

    TypeError:“undefined”不是“in”的有效参数(正在计算“样式中的名称”)

    第6643行。以下是
    jQuery.js
    中的代码:

    // return a css property mapped to a potentially vendor prefixed property
    function vendorPropName( style, name ) {
    
        // shortcut for names that are not vendor prefixed
        if ( name in style ) {   //<---This is the line that causes the error
            return name;
        }
    
        // check for vendor prefixed names
        var capName = name.charAt(0).toUpperCase() + name.slice(1),
            origName = name,
            i = cssPrefixes.length;
    
        while ( i-- ) {
            name = cssPrefixes[ i ] + capName;
            if ( name in style ) {
                return name;
            }
        }
    
        return origName;
    }
    
    //返回映射到潜在供应商前缀属性的css属性
    函数vendorPropName(样式、名称){
    //未加供应商前缀的名称的快捷方式
    
    如果(以样式命名){/对于问题的第2部分,您的
    this
    不是您期望的
    this
    ,因为它的作用域位于
    窗口内。setTimeout()
    函数。您需要在
    setTimeout()的作用域之外获取对
    this
    的引用(或仅获取单击元素的位置)
    。相关代码如下。我更新了您的小提琴。请注意,该函数不考虑边距或填充

    var pos = $(this).position();
    
    // Set timeout
    pressTimer = window.setTimeout(function() 
    { 
        console.log("interval button long click");
    
        $("#edit_interval").css({"left": pos.left + 'px', "top": pos.top + 'px'}).show();
    },1000)
    return false;
    

    (只是一次尝试):你能试试吗:
    (函数($){//你的jQuery代码在这里}(jQuery));
    这可能是jQuery
    noconflict
    mode@karthikr,我应该在哪里添加它?我尝试将它放在我的jQuery代码之前,但它不起作用。请在
    $(document.ready()的位置执行此操作
    这不起作用。谢谢你的尝试!我可以推荐的另一件事是,你可以用普通的js替换min,看看你是否能理解发生了什么。很抱歉没有帮上忙。这解决了这两个问题!这一定是对
    的错误引用。
    。这让我真的卡住了-非常感谢(+1&accept)!