html页面代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* { margin:0; padding:0; }
div.centent {
float:left;
text-align: center;
margin: 10px;
}
span {
display:block;
margin:2px 2px;
padding:4px 10px;
background: # 898 989;
Cursor: pointer;
font-size: 12px;
Color: White;
}
</ style>
<- - introducing the jQuery!>
<Script the src = "../ jQuery / jQuery-1.3.1.js "type =" text / JavaScript "> </ Script>
<Script type =" text / JavaScript ">
$ (function () {
// to the right
$ ( 'the Add #'). the Click (function () {
// Gets the selected options, delete and append to the other
$. ( '# select1 the option: the selected') the appendTo ( '# Select2');
});
// move left
$ ( '# remove'). click(function() {
$. ( '# Select2 the Option: the Selected') the appendTo ( '# select1');
});
// all moved to the right of
$ (. '# add_all') the Click (function () {
// get all of the options, delete and added to the other
$ ( 'the select1 Option #') the appendTo ( '# Select2');.
});
// all move to the left
(. '# to remove_all') the Click (function () {$
$ ( '# Select2 Option ') .appendTo (' # select1 ');
});
// Double-click option
. $ (' # select1 ') dblclick (function () {// bind double-click events
// get all of the options, delete and append to each other
$ ( "option: selected ", this) .appendTo ( '# select2'); // append to each other
});
//双击选项
$('#select2').dblclick(function(){
$("option:selected",this).appendTo('#select1');
});
});
</script>
</head>
<body>
<div class="centent">
<select multiple="multiple" id="select1" style="width:100px;height:160px;">
<option value="1">选项1</option>
<option value="2">选项2</option>
<option value="3">选项3</option>
<option value="4">选项4</option>
<option value="5">选项5</option>
<option value="6">选项6</option>
<option value="7">选项7</option>
</select>
<div>
<span id="add" >选中添加到右边>></span>
<span id="add_all" >全部添加到右边>></span>
</div>
</div>
<div class="centent">
<select multiple="multiple" id="select2" style="width: 100px;height:160px;">
<option value="8">选项8</option>
</select>
<div>
<span id="remove"><<选中删除到左边</span>
<span id="remove_all">& lt; & lt; Remove All to the left </ span> </ HTML> </ body> </ div>
</ div>
-------------------------------------------------- ------------------------------------------------
allow designated option option value is selected:
<sELECT ID = "userTypeSub" name = "userTypeSub">
<option value = ""> whole </ option>
<option value = "0"> access number Log </ option>
<option value = "1"> broadband No. Log </ Option>
</ SELECT>
$ ( "# userTypeSub") Val ( ". 1");.
or
$ ( 'select [name = " userTypeSub"] option [value = "1 ".] ') attr (" selected "," true ");
the code represents a number Log in to make broadband is selected.
-------------------------------------------------- ------------------------------------------------
<
function(){
var date = new Date();
var preMonth = date.getMonth();
//让一个月被选中
j$("select[name='month'] option[value='"+preMonth+"']").attr("selected", "true");
}
);
<select name="month">
<option value="1">一月</option>
<option value="2">二月</option>
<option value="3">三月</option>
</select>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* { margin:0; padding:0; }
div.centent {
float:left;
text-align: center;
margin: 10px;
}
span {
display:block;
margin:2px 2px;
padding:4px 10px;
background: # 898 989;
Cursor: pointer;
font-size: 12px;
Color: White;
}
</ style>
<- - introducing the jQuery!>
<Script the src = "../ jQuery / jQuery-1.3.1.js "type =" text / JavaScript "> </ Script>
<Script type =" text / JavaScript ">
$ (function () {
// to the right
$ ( 'the Add #'). the Click (function () {
// Gets the selected options, delete and append to the other
$. ( '# select1 the option: the selected') the appendTo ( '# Select2');
});
// move left
$ ( '# remove'). click(function() {
$. ( '# Select2 the Option: the Selected') the appendTo ( '# select1');
});
// all moved to the right of
$ (. '# add_all') the Click (function () {
// get all of the options, delete and added to the other
$ ( 'the select1 Option #') the appendTo ( '# Select2');.
});
// all move to the left
(. '# to remove_all') the Click (function () {$
$ ( '# Select2 Option ') .appendTo (' # select1 ');
});
// Double-click option
. $ (' # select1 ') dblclick (function () {// bind double-click events
// get all of the options, delete and append to each other
$ ( "option: selected ", this) .appendTo ( '# select2'); // append to each other
});
//双击选项
$('#select2').dblclick(function(){
$("option:selected",this).appendTo('#select1');
});
});
</script>
</head>
<body>
<div class="centent">
<select multiple="multiple" id="select1" style="width:100px;height:160px;">
<option value="1">选项1</option>
<option value="2">选项2</option>
<option value="3">选项3</option>
<option value="4">选项4</option>
<option value="5">选项5</option>
<option value="6">选项6</option>
<option value="7">选项7</option>
</select>
<div>
<span id="add" >选中添加到右边>></span>
<span id="add_all" >全部添加到右边>></span>
</div>
</div>
<div class="centent">
<select multiple="multiple" id="select2" style="width: 100px;height:160px;">
<option value="8">选项8</option>
</select>
<div>
<span id="remove"><<选中删除到左边</span>
<span id="remove_all">& lt; & lt; Remove All to the left </ span> </ HTML> </ body> </ div>
</ div>
-------------------------------------------------- ------------------------------------------------
allow designated option option value is selected:
<sELECT ID = "userTypeSub" name = "userTypeSub">
<option value = ""> whole </ option>
<option value = "0"> access number Log </ option>
<option value = "1"> broadband No. Log </ Option>
</ SELECT>
$ ( "# userTypeSub") Val ( ". 1");.
or
$ ( 'select [name = " userTypeSub"] option [value = "1 ".] ') attr (" selected "," true ");
the code represents a number Log in to make broadband is selected.
-------------------------------------------------- ------------------------------------------------
<
function(){
var date = new Date();
var preMonth = date.getMonth();
//让一个月被选中
j$("select[name='month'] option[value='"+preMonth+"']").attr("selected", "true");
}
);
<select name="month">
<option value="1">一月</option>
<option value="2">二月</option>
<option value="3">三月</option>
</select>