English 中文(简体)
使用超文本的Java字典,将“onSOMETHING”或一劳永逸地添加一份活动清单。
原标题:Use HTML JavaScript attribute "onSOMETHING" or add a Event Listener on Script for all elements at once?

我使用的是一份从档案中获取一名外部JSON的文字,并穿透其物体,并在所有文件完成之后,在地狱中形成超文本。 但是,我想知道,它是否更好地利用了例如:onclick htmlvide(直接输入代码)或在其课程中加上一个活动听众,在接通到OMM之后,将 Java成像。

Is it the same speed or one is faster than the other and why? I use a lot of HTML objects so I really need to know that, to get the best performance of it.

最佳回答

我建议使用一些简单的event delegation:

// works on existing and future elements
// since we are attaching to the parent
var d = document;
d.getElementById("theParentOfAppendedElements").onclick = function (e) {
    if(e.target.tagName.toLowerCase() === "something" 
        && e.target.className === "appended") {
        // do something
    }
}
问题回答

在个人方面,我总是使用不侵犯性的 j。 我把所有文字放在单独的js档案中,所有事件都放在这些文字中。 因此,我不再把标记和文字混为一谈,我缩小了标识的规模。 这限制了带宽的消费。 由于 j纸档案由客户浏览器整理,网站的运行情况有所改善。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签