小编fek*_*lek的帖子

两个div具有相同的parentNode但不同的offsetParent

我用两个具有相同元素的函数调用此函数parentNode:

var test = function(target, div){
     alert(div.parentNode == target.parentNode );    // gives true
     alert(div.offsetParent == target.offsetParent); // gives true
     div.setAttribute("style", "position:relative; float:left; height:" + target.offsetHeight + "px;");
     alert(div.parentNode == target.parentNode);     // gives true
     alert(div.offsetParent == target.offsetParent); // gives false!!!
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,两个元素都具有相同的父元素,这意味着它们位于DOM树的同一分支内,它们offsetParent为何会有所不同?

我在这里注意到div具有相对位置,这似乎是原因,因为当我删除它时两个警报都给出了真实.(但通常元素的位置不应影响它offsetParent)

/*我在更多的调查之后编辑了这个函数它应该显示更多问题所在*/我在FF和Chrome上得到了相同的结果.两个元素的parentNode是一个table-td

谢谢你的回答.

html javascript css

9
推荐指数
1
解决办法
282
查看次数

即使其中一个查询失败,pdo也会在多个查询中返回true

这里的深层问题是知道PDO何时返回true和false.

文档说如果失败成功为假则为true.那么MySQL的成功和失败是什么?

这是我当前的问题:我在一个PDO执行中将所有查询一起发送,即使foreign_id不应该为NULL,它也会返回true:

SET @id := NULL; SELECT id INTO @id FROM ? WHERE id = ? AND to_user = ?;
INSERT INTO hidden_notifications(table_name, foreign_id) VALUES (?, NULL);
Run Code Online (Sandbox Code Playgroud)

但如果我只发送

INSERT INTO hidden_notifications(table_name, foreign_id) VALUES (?, NULL);
Run Code Online (Sandbox Code Playgroud)

false被正确返回.

NB NULL仅用于测试目的,通常由@id替换.

我进一步尝试了解PDO的行为:

INSERT INTO hidden_notifications(table_name, foreign_id) VALUES (?, ?);
INSERT INTO hidden_notifications(table_name, foreign_id) VALUES (?, NULL);
Run Code Online (Sandbox Code Playgroud)

这里第一个插入是正确的,第二个插入没有,PDO返回true ..我开始认为只有一个查询成功时PDO返回true.

你可以向我解释一下,所以我知道如何处理我的数据库.因为我的所有计划都基于这个原则:

execute('BEGIN')
execute(myquery) // which can be many selections, insertions updates together in one string
if succed execute('COMMIT')
else execute('ROLLBACK')
Run Code Online (Sandbox Code Playgroud)

php mysql pdo

6
推荐指数
1
解决办法
699
查看次数

JQuery .find有多个选择器

我有这个问题与Jquery项[c]被很好地定义为HTMLElement但是当我使用.find与多个选择器时,我得到这个错误:

TypeError: X[g].exec is not a function
http://code.jquery.com/jquery-latest.min.js
Run Code Online (Sandbox Code Playgroud)

当我查看一些手表时,我得到了下图中的内容:

$(items[c]).find('.received') 工作正常并返回一些元素,因为有该类的元素

$(items[c]).find('.receive') 也可以正常工作并返回零元素,因为该类没有元素.

$(items[c]).find('.received.unseen')返回undefined和bug.那么这里发生了什么?

在此输入图像描述

编辑:这是调试器firefox中的内容[c] 在此输入图像描述

编辑:这是我有bug的功能,我切换到jquery 2.1.1:

function updateUnseenBell(){
    var m;
    for (var c in items)
        if (items.hasOwnProperty(c) && (m = items[c].gEbCN("chat-partner-tab")[0])) {
        if($(items[c]).find('.received.unseen:not(.shown)').length > 0){
            if (!(m.l2_newMsgBell)) {
                m.appendChild(m.l2_newMsgBell = newMsgBell.cloneNode());
                playSound("message");
            }
        } else if (m.l2_newMsgBell) {
            m.removeChild(m.l2_newMsgBell);
            delete m.l2_newMsgBell;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我把它减少到调试的最小值,但仍然得到相同的错误:

function updateUnseenBell(){
    for (var c in items) {
        if (items.hasOwnProperty(c)) {
            if ($(items[c]).find('.received.unseen:not(.shown)').length > 0) {
                alert(1);
            } else { …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-selectors

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

css ×1

html ×1

javascript ×1

jquery ×1

jquery-selectors ×1

mysql ×1

pdo ×1

php ×1