- Ian Collins。 不知道,从未使用过它。 input.onchange = mychangefunction; - 兰迪 comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周 Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices / 是的。值必须是DOMString类型。 例如,HTML onclick属性和DOM属性之间并没有真正的标准化连接。最接近的是 < URL:http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration-html40> 要遵循标准,您应该使用Events DOM方法 (addEventListener等)来处理事件处理程序。 / L - Lasse Reichstein Nielsen - lr*@hotpop.com DHTML死亡色彩:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> ''没有判断力的信仰只会降低精神神圣。'' I am curious if there is a benefit to set attributes directly, in myjavascript, or to use setAttribute. For example, I have this:var input = document.createElementNS(xhtmlNS, ''input'');input.setAttribute(''width'', ''20em''); I could have just called input.width=''20em'' When is each better to use, or is there no difference between them? Also, it is improper to use setAttribute in such a way:input.setAttribute(''onchange'', mychangefunction) Thank you for any help. 解决方案 Have you tried it? I haven''t. Even if it does work, it would be obscure, just assign event handlersdirectly. --Ian Collins. No idea, never used it before. input.onchange = mychangefunction; --Randycomp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weeklyJavascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/ Yes. The value must be of type DOMString.There isn''t really a standardized connection between, e.g., the HTMLonclick attribute and a DOM attribute. The closest is<URL:http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration-html40>To follow standards, you should use the Events DOM methods(addEventListener, etc) to handle event handlers. /L--Lasse Reichstein Nielsen - lr*@hotpop.comDHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>''Faith without judgement merely degrades the spirit divine.'' 这篇关于直接使用setAttribute或set属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 03:21