selecttoselectjQuery插件的使用方法
我一直想在网上找这样的东西,但从来没有找到过,所以我自己写了一本。希望能帮我看看童鞋们。如果有人有更强大的插件,请与我保持一个地址,非常感谢!
结果如下:
代码如下:
复制代码代码如下所示:
(函数($){)
美元。FN。selecttoselect =功能(选项){
如果(类型(选项)=字符串){
var $ = $(这个);
如果(选项= =getselectedids ){
var;
var arr = $(+ $ this.attr # (ID)+sereselect选项);
arr.each(功能(我){)
如果(arr.length-1 = =我){
ID =美元(这)。Attr(ID);
其他{ }
ID =美元(这)。Attr(ID)+
}
});
返回ID;
}
返回$此;
}
var默认值= {
尺寸:10,
opselect:{ },
opreselect:{ },
OnChange:功能(数据){ }
};
VaR选择=美元。扩展(默认值,选择);
返回this.each(函数(){()
var $ = $(这个);
var;
;
;
;
对于(var i = 0;i < opts.opselect.length;i++){
STR + = +选择。opselect {我}姓名+ 。
}
;
;
;
;
;
;
;
;
>;
;
;
;
;
;
;
;
;
;
;
;
;
对于(var i = 0;i < opts.opreselect.length;i++){
STR + = +选择。opreselect {我}姓名+ 。
}
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
this.html美元(STR);
/ /需要juqery UI插件
this.find美元(按钮)。Button();
+ $这个属性(ID)+
this.find美元(+ $ this.attr # (ID)+btnselectall )(点击(功能){
this.find美元(选项{名称=+ this.attr美元(ID)+opselect})。每个(功能(我){)
$(+ $(this)(文本)+ ),AppendTo(+ $ this.attr #(ID)+sereselect );
});
$(+ $ this.attr # (ID)+seselect )(空);
Opts.onChange($(选项{名称=+ this.attr美元(ID)+opreselect}))
});
$(+ $ this.attr # (ID)+点击(btnreselectall )
函数(){
$(选项{名称=+ this.attr美元(ID)+opreselect})。每个(功能(我){ {)
$(+ $(this)(文本)+ ),AppendTo(+ $ this.attr #(ID)+seselect );
});
$(+ $ this.attr # (ID)+sereselect )(空);
Opts.onChange($(选项{名称=+ this.attr美元(ID)+opreselect}))
}
);
$(+ $ this.attr # (ID)+点击(btnselectone )
函数(){
如果($(+ $ this.attr # (ID)+seselect )(瓦迩)){
无功arrchecked = $(+ $ this.attr # (ID)+seselect选项:检查)
对于(var i = 0;i < arrchecked.length;i++){
$(+ $(arrchecked {我})(文本)+ ),AppendTo(+ $ this.attr #(ID)+sereselect );
$(选项{名称=+ this.attr美元(ID)+opselect})。每个(功能(J){ {)
如果(这个值= = arrchecked {我},{价值)
美元(这个);
}
});
}
Opts.onChange($(选项{名称=+ this.attr美元(ID)+opreselect}))
}
其他的
{
美元。dashboard.alert(尖
}
}
);
$(+ $ this.attr # (ID)+点击(btnreselectone )
函数(){
如果($(+ $ this.attr # (ID)+sereselect )(瓦迩)){
无功arrchecked = $(+ $ this.attr # (ID)+sereselect选项:检查);
对于(var i = 0;i < arrchecked.length;i++){
$(+ $(arrchecked {我})(文本)+ ),AppendTo(+ $ this.attr #(ID)+seselect );
$(选项{名称=+ this.attr美元(ID)+opreselect})。每个(功能(J){ {)
如果(这个值= = arrchecked {我},{价值)
美元(这个);
}
});
}
Opts.onChange($(选项{名称=+ this.attr美元(ID)+opreselect}))
}
其他的
{
美元。dashboard.alert(尖
}
}
);
$(+ $ this.attr # (ID)+点击(btnup )
函数(){
如果($(+ $ this.attr # (ID)+sereselect )(。Val)(+ $ this.attr #美元(ID)+sereselect选项:选中)。长度= = 1){
VaR指标= $(+ $ this.attr # (ID)+sereselect ){ 0 }。SelectedIndex;
$($(选项{名称=+ this.attr美元(ID)+opreselect}){指数})。后($(选项{名称=+ this.attr美元(ID)+opreselect}){ })指数;
Opts.onChange($(选项{名称=+ this.attr美元(ID)+opreselect}))
}
其他的
{
美元。dashboard.alert(尖
}
}
);
$(+ $ this.attr # (ID)+点击(btndown )
函数(){
如果($(+ $ this.attr # (ID)+sereselect )(。Val)(+ $ this.attr #美元(ID)+sereselect选项:选中)。长度= = 1){
VaR指标= $(+ $ this.attr # (ID)+sereselect ){ 0 }。SelectedIndex;
$($(选项{名称=+ this.attr美元(ID)+opreselect}){指数})。在($(选项{名称=+ this.attr美元(ID)+opreselect}){指数+ 1 });
Opts.onChange($(选项{名称=+ this.attr美元(ID)+opreselect}))
}
其他的
{
美元。dashboard.alert(尖
}
}
);
});
};
}(jQuery);
使用方法:
复制代码代码如下所示:
无功opselect1 = { {编号:1,名称:'tip1},{编号:2,名称:'tip2} };
无功opreselect1 = { {编号:3,名称:'tip3},{编号:3,名称:'tip3} };
$(# selecttoselect1)。SelectToSelect({
尺寸:10,
opselect:opselect1,
opreselect:opreselect1,
OnChange:功能(选项){
ID = $(var# selecttoselect1)。SelectToSelect(getselectedids );
}
});