如果我创建元素并像片段 1 那样以编程方式设置元素属性,还是像片段 2 那样写出 innerHTML,这是否重要?使用答案之一中建议的模板库怎么样?
片段 1
var link_element,
image_element;
// create image element
image_element = $A.createElement('img');
image_element.className = "bookmark_image";
image_element.name = "bo_im";
image_element.src = bookmark_object.favicon;
// create link element
link_element = $A.createElement('a');
link_element.innerHTML = bookmark_object.title;
link_element.href = bookmark_object.url;
link_element.name = "bookmark_link";
link_element.className = "bookmark_link";
link_element.target = "_blank";
// append now
片段 2
'<img name="bo_im class="bookmark_image" src="' + val.favicon + '">' +
'<a target="_blank" name="bookmark_link" class="bookmark_link" href = "' + val.url + '" id="' + val.id + '">' + val.title + '</a>' +
// set to innerHTML now