`

jQuery追加新的元素,便于排序

阅读更多
var element = document.createElement(tagName);

// create a new div element
  // and give it some content
  newDiv = document.createElement("div");
  newContent = document.createTextNode("Hi there and greetings!");
  newDiv.appendChild(newContent); //add the text node to the newly created div.

  // add the newly created element and it's content into the DOM
  my_div = document.getElementById("org_div1");
  document.body.insertBefore(newDiv, my_div);


<ul id="ul_collect" style="position: absolute;left: -75px;width: 940px;">
		<li transId="_TRANS_ID.NUONUO" transName="" url="" class="infoBtn swapImage fucai" style="background-image: url('/images/collect/zyt_btn.png');">
			诺诺</li>
		<li transId="_TRANS_ID.YOUBANG" transName="" url="" class="infoBtn swapImage fucai" style="background-image: url('/images/collect/zyt_btn.png');">
			友邦</li>
		<li transId="_TRANS_ID.GUANGFA" transName="" url="" class="infoBtn swapImage fucai" style="background-image: url('/images/collect/wlbtysh_btn.png');">
			广发银行</li>
		<li transId="_TRANS_ID.PINGAN" transName="" url="" class="infoBtn swapImage fucai" style="background-image: url('/images/collect/wlbtysh_btn.png');">
			平安银行</li>
	</ul>


_STAGE.currentBiz = "pingan|nuonuo";


var currentBizArr = _STAGE.currentBiz.split("|");
		jQuery("#ul_collect").empty();
		for(var i = 0; i < currentBizArr.length; i++){
			jQuery("#ul_collect").append(document.createElement("li")).find("li").eq(i).attr("transId",
			"_TRANS_ID."+(currentBizArr[i].toUpperCase())).addClass("infoBtn swapImage fucai").attr("style", 
			"background-image: url('/images/collect/wlbtysh_btn.png');").text(currentBizArr[i].toUpperCase());
		}
		
		jQuery("li").css({
			"width" : "419",
			"height" : "91",
			"border" : "0",
			"vertical-align" : "middle",
			"font-size" : "22px",
			"color" : "white",
			"line-height" : "3.5"
		}).addClass("text_center");


、、追加词典对应值:
// 信息收集业务文字
	currentBizText : {
		"guangfa" : "广发银行",
		"pingan" : "平安银行",
		"nuonuo" : "诺诺",
		"youbang" : "友邦"
	},

for(var i = 0; i < currentBizArr.length; i++){
			jQuery("#ul_collect").append(document.createElement("li")).find("li").eq(i).attr("transId",
			"_TRANS_ID."+(currentBizArr[i].toUpperCase())).addClass("infoBtn swapImage fucai").attr("style", 
			"background-image: url('/images/collect/wlbtysh_btn.png');").text(this.currentBizText[currentBizArr[i]]);
		}


this.currentBizText[currentBizArr[i]]
分享到:
评论

相关推荐

    常用的jquery案例

    #### 十、如何从一个未排序的集合中找出某个元素的索引号 **知识点:** - **`.prevAll()` 方法:** 获取匹配元素的所有同级元素的集合。 **示例代码分析:** ```javascript $("ul &gt; li").click(function(){ var ...

    jQuery API

    jQuery 提供了一系列方法来操作DOM,包括`$(selector).html()`(设置或获取元素的HTML内容),`$(selector).append()`(在元素内部追加内容),`$(selector).prepend()`(在元素内部预置内容),`$(selector).remove...

    JQuery 的使用(1)

    1. **添加/删除元素**: `append()`、`prepend()`可以向元素内部追加或预置内容;`remove()`用来删除元素。 2. **修改属性**: `attr()`用于设置或获取元素的属性,如`$("img").attr("src", "newImage.jpg")`更改图片...

    jQuery实现带分组数据的Table表头排序实例分析

    6. 排序完成后,我们需要将排序后的行重新放入一个新的文档片段(DocumentFragment)中,然后将这个文档片段追加到原表格的body中。 7. 最后,我们需要记录当前列的索引,并更新表头单元格的显示,以反映当前的排序...

    JS实现的表格行上下移动操作示例

    此外,为了提升用户体验,我们可能会使用一些现代的库或者框架,比如jQuery,来简化DOM操作和提供更好的跨浏览器兼容性。 值得注意的是,本示例为了演示的需要,使用了`javascript:void(0)`作为超链接的`href`属性...

Global site tag (gtag.js) - Google Analytics