问题标签 [dom-node]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1155 浏览

jquery - jQuery 定位嵌套列表

我首先要实现的是测试“li”是否嵌套了“ul”,如果是,则在单击时显示嵌套的“ul”。这运作良好;但是,if 语句对每个“li”都返回 true,而不仅仅是那些有子“ul”的语句。这意味着没有子菜单的链接不起作用,因为 e.preventDefault() 被调用。

感谢帮助!

0 投票
3 回答
91 浏览

javascript - 使用 jquery 获取行的总和

我正在尝试创建一个简单的总计,我的基本 html 如下所示:

jQuery函数:

这目前在函数末尾累积添加到总数中,而不是按行。

我希望这将是一个简单选择器的情况var total = $(this).parent().find('.total');(我也尝试过var total = $(this).closest('.total');.

在将总和输出到.total元素之前,我是否需要一个空数组来推送总数?或者是否有内置的 jquery 应该使用正确的选择器返回总和?

JSFIDDLE:https ://jsfiddle.net/lharby/y991hkf6/

0 投票
0 回答
602 浏览

jquery - 如何使用jQuery销毁()特定元素并在克隆上重新初始化

我有以下问题:

我为我的应用程序使用了超薄图像裁剪插件,但是在克隆 html 并重新初始化插件时遇到了一些问题。

我正在销毁对象,以便在克隆新字段后使插件正常工作。问题是我克隆时选择的图像正在被删除。有更好的方法吗?

html代码:

jQuery代码:

0 投票
1 回答
2222 浏览

xml - how to add a xml node to a symfony Crawler()

I need to manage xml documents in saymfony.

I've got no problem to get the xml into a Crawler() instance, modify existing node and after it, put the xml into a file.

But i can't add new node.

When i try to add a new node with appendChild method to the parent, i've got:

wrong document error

And when i try the add method to the crawler, i've got:

impossible to add two differents sources to the crawler?

What can i do to add a simple node to an existing crawler?

Thanks for any response

0 投票
1 回答
368 浏览

php - 如何在 PHP 中使用 DOMNode 将 HTML 插入文本节点

我有一个 PHP 脚本,它使用 DOMDocument 和 DOMXPath 来查找和替换 HTML 模板中的合并代码。一个简单的例子可能是:

以下代码基于键与合并字段匹配的关联数组替换字段:

这运作良好。

但是,一些合并代码需要将 HTML 替换到其中:

替换正在发生,但 HTML 正在被转义,这在大多数情况下可能是一个明智的想法。

我可以解决这个问题吗?

0 投票
0 回答
190 浏览

javascript - 如何获取文本节点的原始值?

假设我有以下内容:

nodes[0]然后在(ie nodes[0].data, nodes[0].nodeValue, nodes[0].textContent, )的所有领域中nodes[0].wholeText我得到<. 我可以以某种方式检索文本节点的“原始”值吗?在这种情况下&lt;。或者是首先检索它解析的唯一选择,然后转义 html 有点像这样:

注意:我有意识地选择childNodes以获得文本节点以及非文本节点。

0 投票
1 回答
627 浏览

javascript - 在解析的 HTML DOM 中查找和更改元素

我收到一个响应 ajax 请求的 HTML 字符串。它是一个带有许多分层子节点的大型 HTML 字符串。

我使用解析它

将其转换为 DOM。现在我想更改具有特定 ID 的子节点的内容,然后重新生成 HTML。

问题是当我使用 jQuery 方法选择一个 dom 元素进行更改时,它会返回该特定节点和

只需将该节点更改为 HTML。

我尝试过以下代码示例

或者

问题是它只返回 span#element-id 并且当应用 html() 时,生成的 html 只有 span 文本。

如何生成完整的 html 并更改特定节点?

0 投票
1 回答
104 浏览

java - How to get surrounding text of a node?

I am playing around with nutch. I am trying to write something which also include detecting specific nodes in the DOM structure and extracting text data from around the node. e.g. text from parent nodes, sibling nodes etc. I researched and read some examples and then tried writing a plugin that will do this for an image node. Some of the code,

This doesn't seem to work properly. img tag gets detected, Image name and URL gets retrieved but no more help. the getSurroundingText module looks too ugly, I tried but couldn't improve it. I don't have clear idea from where and how can I extract text which could be related to the image. Any help please?

0 投票
1 回答
88 浏览

javascript - 使用未转义的 HTML 将元素的内容作为字符串获取

我正在使用xmldomnpm 库中的解析器,它基于 DOMNode 对象模型。具有以下代码:

我想获取toFetch标签的内容,作为一个字符串,里面包含所有未转义的 HTML 标签,并且没有toFetch标签本身。

我所拥有的是:

它有效,但它给了我带有toFetch周围标签的字符串。我怎样才能只获得内容?

0 投票
1 回答
84 浏览

reactjs - reCAPTCHA:不要访问 .getDOMNode()

我一直在尝试在我的反应应用程序中实现 reCAPTCHA,但是当一切似乎都正常时,我检查了控制台并发现了这个警告:

Warning: ReactDOMComponent: Do not access .getDOMNode() of a DOM node; instead, use the node directly. This DOM node was rendered by 'reCAPTCHA'.

我当前的软件包版本:

试图通过降级来解决这个问题,react@0.14.0但它没有帮助。

编辑:

代码:

和服务器端: