Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我现在正在玩 PHP 的DOMDocument。正如问题所述,这两种方法之间有什么区别(除了需要将 DOMAttr 传递给 setAttributeNode 之外)以及应该在什么情况下使用它们?
我记得,里面没有很多。除了您已经确定的那个之外,主要区别是setAttributeNode不能用于同时为属性设置值,而只能用于设置属性的名称。
setAttributeNode
实际上,它是一种在 DOM 之外准备属性以供稍后插入的方法。
setAttribute是一种更快的方法;它允许规定名称和值。
setAttribute