jqueryEasyUI TagBox獲取值的方法

最近由於需求,需要用到這個控件。在編寫過程中出現了幾個小插曲,記錄下來。

下面是測試代碼,引入jquery和jqueryeasyui後可以直接運行。

<body>
	<div style="margin:20px 0;"></div>
	<div class="easyui-panel" style="width:100%;max-width:400px;padding:30px 60px;">
		<input class="easyui-tagbox" value="Apple,Orange" label="Add a tag1" style="width:100%" id="testTag">
	</div>
	<input type="button" οnclick="test()" value="test">

</body>
	<script>
	var index=0;
		function test(){
			var oldValue = $("#testTag").val();
			$("#testTag").tagbox({
				value: ['Apple1','Orange1']
			});
			index+=1;
			var arr = $("#testTag").tagbox("getValues");
			console.log(arr.toString());
			//console.log(oldValue);
			//console.log(oldValue + "," + new Date());
		}
	</script>

1,通過“getValue”不能獲取所有的值,只能獲取到第一個值

$("#testTag").tagbox("getValues");

修改爲getValues即可以獲取到一個包含所有值得數組。

 ["Apple1", "Orange1"]

2,這個jQueryeasyUI的控件要求jQueryeasyUI的版本必須在1.5以上,版本過低不能使用。

3,設置值得方式也有兩種

      a.通過setValues.

$("#testTag").tagbox("setValues",[1,2,3s]);

      b.通過初始化的方式

$("#testTag").tagbox({
	value: ['1','2']
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章