js动态添加HTML标签
2017-12-01 11:09
423 查看
function addElement_imageText(img,title,source,view_count,publish_time,url,article_type,newsid,category_chn){ /*var reconmendDiv = document.getElementById("m-newList"); var reconmendDivWarp = document.createElement("div"); reconmendDivWarp.setAttribute("class", "wrap"); reconmendDiv.appendChild(reconmendDivWarp); var ul = document.createElement("ul"); reconmendDivWarp.appendChild(ul);*/ var ul = document.getElementById("newListul"); var li = document.createElement("li"); li.setAttribute("class", "fl image-text-li"); ul.appendChild(li); var lidiv = document.createElement("div"); lidiv.setAttribute("class", "newsdetail"); li.appendChild(lidiv); var imgdiv = document.createElement("div"); imgdiv.setAttribute("class", "fl image-text-li"); var liimg = document.createElement("img"); liimg.src = img; lidiv.appendChild(liimg); if(itypeItem==1||itypeItem==undefined){ var typediv = document.createElement("div"); if(category_chn==""||category_chn.length>3){ category_chn = "其他"; } typediv.innerHTML = category_chn; typediv.setAttribute("class", "typetext"); lidiv.appendChild(typediv); } var lip = document.createElement("p"); lip.innerHTML = title.substring(0,25); lidiv.appendChild(lip); var span1 = document.createElement("span"); span1.setAttribute("class", "firstspan"); span1.innerHTML = source.substring(0,5); lidiv.appendChild(span1); var span2 = document.createElement("span"); span2.innerHTML = view_count+"评论"; span2.setAttribute("class", "secendspan"); lidiv.appendChild(span2); var span3 = document.createElement("span"); span3.setAttribute("class", "lastspan"); span3.innerHTML = publish_time; lidiv.appendChild(span3); li.onclick=function(){//给p标签添加onclick事件 Avatar.push(['track', ['click', 'detail', '', {tab:category_chn, id:newsid}, 0]]); window.open(url); }; }
相关文章推荐
- tools - js动态添加任何html标签
- tools - js动态添加任何html标签
- iOS中动态注入JavaScript方法。动态给html标签添加事件
- Js脚本:动态添加HTML自定义属性以及处理html元素的自定义属性(兼容Firefox和IE)
- JS-----------动态生成的html标签,在使用js获取不到
- JS简单实现动态添加HTML标记的方法示例
- Html+js实现表格可编辑,并能动态添加删除行
- 把html标签里的内容,添加到js数组中
- JS脚本实现动态给标签控件添加事件的方法
- js 动态添加标签(新增一行,其实很简单,就是几个函数的应用)
- jquery动态添加带有样式的HTML标签元素
- 给Ajax返回的HTML标签动态添加样式的方法
- 动态添加HTML标签中单引号,双引号的嵌套问题
- js实现html节点、CSS样式、事件的动态添加以及html覆盖层的添加
- js 动态添加标签(新增一行,其实很简单,就是几个函数的应用)
- 给用js动态创建的标签添加事件
- js动态添加select标签元素的下来选项
- js 动态添加标签
- js中加载并解析xml文件, 动态添加标签,控件
- 用js动态添加select标签的option