Html in select controls on

  http://community.csdn.net/Expert/topic/4200/4200845.xml?temp=.105755 

  / / Delete all the selected items 
  <PUBLIC:METHOD NAME="deleted" /> 
  / / Check all items 
  <PUBLIC:METHOD NAME="selectAll" /> 
  / / Uncheck the items 
  <PUBLIC:METHOD NAME="selectNone" /> 
  <PUBLIC:ATTACH EVENT="onclick" ONEVENT="doClick()" /> 
  <PUBLIC:ATTACH EVENT="ondblclick" ONEVENT="doDblClick()" /> 
  <script language="JScript"> 
  / / Delete from the list box, all the selected items.    If obj as null, while the list for its own box. 
  function deleted (obj) ( 
  if (obj == null) obj = element; 
  if (obj.tagName! = "SELECT") return; 
  for (var i = obj.options.length-1; i> = 0; i -) ( 
  if (obj.options [i]. selected) ( 
  obj.options.remove (i); 
  ) 
  ) 
  ) 
  / / Selected to the list box set of all the items.    If obj as null, while the list for its own box. 
  function selectAll (obj) ( 
  if (obj == null) obj = element; 
  if (obj.tagName! = "SELECT") return; 
  var length = obj.options.length; 
  for (var i = 0; i <length; i + +) ( 
  obj.options [i]. selected = true; 
  ) 
  ) 
  / / Cancelled given the list box all selected items.    If obj as null, while the list for its own box. 
  function selectNone (obj) ( 
  if (obj == null) obj = element; 
  if (obj.tagName! = "SELECT") return; 
  var length = obj.options.length; 
  for (var i = 0; i <length; i + +) ( 
  obj.options [i]. selected = false; 
  ) 
  ) 
  / / Check whether obj list box options already exist opt 
  function optionExists (obj, opt) ( 
  var length = obj.options.length; 
  for (var i = 0; i <length; i + +) ( 
  if (obj.options [i]. text == opt.text & & obj.options [i]. value == opt.value) / / If one of the options and the value of a given text with the option of the same, that存在. 
  return true; 
  ) 
  return false; / / If it does not exist, then returns false 
  ) 
  / / Will be selected in the list box obj1 items obj2 added to the list box, check = true that do not add to obj2 in the repeat of the 
  function add (obj1, obj2, check) ( 
  for (var i = 0; i <obj1.options.length; i + +) ( 
  if (obj1.options [i]. selected) (/ / If the option is selected, you will need to join in obj2. 
  if (check) (/ / the need for repetitive inspection 
  if (optionExists (obj2, obj1.options [i])) (/ / If there obj2 list box designated option, the next cycle 
continue;
  ) 
  ) 
  var opt = obj1.options [i]. cloneNode (false); 
  opt.text = obj1.options [i]. text; 
  obj2.options.add (opt); / / options will be added to the ojb2. 
  ) 
  ) 
  ) 
  / / Sort, obj object to the list box, order for the sort attributes, desc for the reverse (true-reverse), a bubbling algorithm improved algorithm 
  function orderList (obj, order, desc) ( 
  var chg = null; 
  var flag = true; / / whether to proceed with the exchange of signs 
  var m = null; 
  var n = null; 
  var len = obj.options.length – 1; 
  for (var j = len; j> 0; j -) ( 
  flag = true; 
  for (var k = 0; k <j; k + +) ( 
  eval ( "m = parseFloat (obj.options [k]." + order + ");"); 
  eval ( "n = parseFloat (obj.options [k +1]." + order + ");"); 
  if (desc) (/ / If the reverse order, the exchange m and n 
  var tt = m; 
  m = n; 
  n = tt; 
  ) 
  if (m> n) (/ / If m> n exchange of the two options 
  chg = obj.options [k]. cloneNode (false); 
  chg.text = obj.options [k]. text; 
  obj.options [k] = obj.options [k +1]. cloneNode (false); 
  obj.options [k]. text = obj.options [k +1]. text; 
  obj.options [k +1] = chg.cloneNode (false); 
  obj.options [k +1]. text = chg.text; 
  flag = false; / / exchanged, as false 
  ) 
  ) 
  if (flag) break; / / If one did not return, the denunciation 
  ) 
  ) 
  / / Incident 
  function doEvent () ( 
  var obj1 = null; / / list of variables Box 1 
  if (window.event.srcElement.tagName == "SELECT") (/ / If the trigger is select elements 
  obj1 = window.event.srcElement; / / obj trigger for the select 
  ) 
  else if (window.event.srcElement.tagName == "OPTION") (/ / If the option is the trigger element 
  obj1 = window.event.srcElement.parentElement; / / obj elements to trigger the parent element select 
  ) 
  else ( 
  if (typeof (window.event.srcElement.ref)! = "undefined") (/ / If the ref is defined 
  obj1 = window.document.getElementById (window.event.srcElement.ref); / / obj for the definition of the elements. 
  if (obj1 == null) return; 
  ) 
else
return;
  ) 
  if (obj1 == null) return; / / if obj is empty, to return to direct. 
  if (obj1.tagName! = "SELECT") return; / / If not return obj list box, to return to direct. 
  if (typeof (obj1.ref) == "undefined") return; / / not specified purpose of the list box, to return to direct. 
  var obj2 = window.document.getElementById (obj1.ref); 
  if (obj2 == null) return; / / did not find purpose of the list box, directly back to 
  if (obj2.tagName! = "SELECT") return; / / not specify the purpose of the list box, to return to. 
  if (typeof (window.event.srcElement.selectall)! = "undefined") (/ / If the definition of the choice of all 
  selectAll (obj1); 
  ) 
  var check = (typeof (obj2.check)! = "undefined")? true: false; / / determine whether the definition of a repeat of the inspection 
  add (obj1, obj2, check); / / add obj1 in ojb2 of selected items. 
  if (typeof (obj1.deleted)! = "undefined") (/ / If the definition of the deletion of the original item 
  deleted (obj1); / / delete the original item 
  ) 
  if (typeof (obj2.order)! = "undefined") (/ / designated need to sort 
  var order = obj2.order; 
  var desc = (typeof (obj2.desc) == "undefined")? false: true; / / determine whether the definition of a reverse 
  orderList (obj2, order, desc); / / Sort 
  ) 
  ) 
  / / Handling click events 
  function doClick () ( 
  if (window.event.srcElement.tagName == "SELECT" | | window.event.srcElement.tagName == "OPTION") return; 
  doEvent (); 
  ) 
  / / Double-click deal with the incident 
  function doDblClick () ( 
  doEvent (); 
  ) 
  </ script> 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
  • DZone
  • Netvouz
  • NewsVine
  • Technorati

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Tags: