28,390
社区成员
发帖
与我相关
我的任务
分享
<Script Language="JavaScript">
function AJax(SpanId,SubmitUrl){
// 测试时候用,根据弹出窗口看生成的代码是否有问题
// window.open(SubmitUrl);
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("您的浏览器不支持AJAX!");
return false;}}}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
set_innerHTML(SpanId, xmlHttp.responseText);
// alert(xmlHttp.responseText);
}
}
xmlHttp.open("GET",SubmitUrl,true);
xmlHttp.setRequestHeader("Content-Type", "text/html");
xmlHttp.send(null);
}
var global_html_pool = [];
var global_script_pool = [];
var global_script_src_pool = [];
var global_lock_pool = [];
var innerhtml_lock = null;
var document_buffer = "";
function set_innerHTML(obj_id, html, time) {
if (innerhtml_lock == null) {
innerhtml_lock = obj_id;
}
else if (typeof(time) == "undefined") {
global_lock_pool[obj_id + "_html"] = html;
window.setTimeout("set_innerHTML('" + obj_id + "', global_lock_pool['" + obj_id + "_html']);", 10);
return;
}
else if (innerhtml_lock != obj_id) {
global_lock_pool[obj_id + "_html"] = html;
window.setTimeout("set_innerHTML('" + obj_id + "', global_lock_pool['" + obj_id + "_html'], " + time + ");", 10);
return;
}
function get_script_id() {
return "script_" + (new Date()).getTime().toString(36)
+ Math.floor(Math.random() * 100000000).toString(36);
}
document_buffer = "";
document.write = function (str) {
document_buffer += str;
}
document.writeln = function (str) {
document_buffer += str + "\n";
}
global_html_pool = [];
var scripts = [];
html = html.split(/<\/script>/i);
for (var i = 0; i < html.length; i++) {
global_html_pool[i] = html[i].replace(/<script[\s\S]*$/ig, "");
scripts[i] = {text: '', src: '' };
scripts[i].text = html[i].substr(global_html_pool[i].length);
scripts[i].src = scripts[i].text.substr(0, scripts[i].text.indexOf('>') + 1);
scripts[i].src = scripts[i].src.match(/src\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|([^\s]*)[\s>])/i);
if (scripts[i].src) {
if (scripts[i].src[2]) {
scripts[i].src = scripts[i].src[2];
}
else if (scripts[i].src[3]) {
scripts[i].src = scripts[i].src[3];
}
else if (scripts[i].src[4]) {
scripts[i].src = scripts[i].src[4];
}
else {
scripts[i].src = "";
}
scripts[i].text = "";
}
else {
scripts[i].src = "";
scripts[i].text = scripts[i].text.substr(scripts[i].text.indexOf('>') + 1);
scripts[i].text = scripts[i].text.replace(/^\s*<\!--\s*/g, "");
}
}
var s;
if (typeof(time) == "undefined") {
s = 0;
}
else {
s = time;
}
var script, add_script, remove_script;
for (var i = 0; i < scripts.length; i++) {
var add_html = "document_buffer += global_html_pool[" + i + "];\n";
add_html += "document.getElementById('" + obj_id + "').innerHTML = document_buffer;\n";
script = document.createElement("script");
if (scripts[i].src) {
script.src = scripts[i].src;
if (typeof(global_script_src_pool[script.src]) == "undefined") {
global_script_src_pool[script.src] = true;
s += 2000;
}
else {
s += 10;
}
}
else {
script.text = scripts[i].text;
s += 10;
}
script.defer = true;
script.type = "text/javascript";
script.id = get_script_id();
global_script_pool[script.id] = script;
add_script = add_html;
add_script += "document.getElementsByTagName('head').item(0)";
add_script += ".appendChild(global_script_pool['" + script.id + "']);\n";
window.setTimeout(add_script, s);
remove_script = "document.getElementsByTagName('head').item(0)";
remove_script += ".removeChild(document.getElementById('" + script.id + "'));\n";
remove_script += "delete global_script_pool['" + script.id + "'];\n";
window.setTimeout(remove_script, s + 10000);
}
var end_script = "if (document_buffer.match(/<\\/script>/i)) {\n";
end_script += "set_innerHTML('" + obj_id + "', document_buffer, " + s + ");\n";
end_script += "}\n";
end_script += "else {\n";
end_script += "document.getElementById('" + obj_id + "').innerHTML = document_buffer;\n";
end_script += "innerhtml_lock = null;\n";
end_script += "}";
window.setTimeout(end_script, s);
}
//取目标select的文字
function change(result){
readyGold = result;
document.myform.ti.focus();
}
//提交功能实现
function tijiao(){
if(readyGold==null)
return false;
else
{
goldLength = document.myform.jieshou.length;
number = 0
for(var i = 0;i<goldLength;i++) //监测禁止重复选择
{
if(readyGold == document.myform.jieshou.options[i].text)
number++;
//document.write("hello");
}
if(number == 0)
{
//jieshouGold = 'document.myform.jieshou'; //定义目标select
document.myform.jieshou.length++; //目标长度加一
selectedIndex = document.myform.jieshou.length - 1;
document.myform.jieshou.options[selectedIndex].text = readyGold;
}
}
}
//删除一个选项
function delect()
{
var i = document.myform.jieshou.length;
if(i != 0)
{
try{
for(var h = 0;h<i;h++)
{
if(document.myform.jieshou.options[h].selected)
{
document.myform.jieshou.options[h]=null;
--h;
}
}
}
catch(s){}
}
}
//删除所有选项
function delectall(){
document.myform.jieshou.length=0;
}
//提交所有选中项
function test(){
var jieshou = document.getElementById("jieshou");
for(var i=0;i<jieshou.length;i++){
jieshou.options[i].selected = true;
}
return true;
}
</Script>
<form name="myform" method="post" action="index.asp" onsubmit="return test()">
<table width="467" border="0">
<tr>
<td width="150" rowspan="3">
<select name="bm" id="bm" style="width:150px;" onChange="AJax('selectSpan','load.asp?bm='+escape(this.options[selectedIndex].value));">
<OPTION value="">请选择部门</option>
<%
sql_open="select 部门 from bm"
set rs_open=conn.execute(sql_open)
if not rs_open.eof then
do while not rs_open.eof
%>
<OPTION value="<%=rs_open("部门")%>"><%=rs_open("部门")%></option>
<%
rs_open.movenext
loop
rs_open.close
end if
%>
</select>
<span id="selectSpan"><select name="yuanshi" size="9" style="width:150px;" onChange="change(this.options[selectedIndex].text)">
<%
sender=session("user_name")
sql_open="select 用户名 from [user]"
set rs_open=conn.execute(sql_open)
if not rs_open.eof then
do while not rs_open.eof
%>
<OPTION value="<%=rs_open("用户名")%>"><%=rs_open("用户名")%></option>
<%
rs_open.movenext
loop
rs_open.close
end if
%>
</select></span>
</td>
<td colspan="2" align="center"><input type="button" value="删除全部" onClick="delectall()"></td>
<td colspan="2" rowspan="3"><select name="jieshou" id="jieshou" style="width:150px;" size="10" multiple="multiple">
</select></td>
</tr>
<tr>
<td width="74" align="center"><input name="ti" type="button" onClick="tijiao()" value="选取>>"></td>
<td width="74" align="center"><input type="button" name="shan" value="<<删除" onClick="delect()"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Submit" value="提交"></td>
</tr>
<tr>
<td colspan="5">
<%
abc=request.Form("jieshou")
response.Write(abc)
%></td>
</tr>
</table>
</form>