关于AJAX js获取数组的问题

wangqiao518999518999 2009-08-31 05:09:36
当我用Var A 变量获取一个List数组的时候
当我在Split(A)的时候,会有问题,分解不了
Code代码

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.OracleClient;
using System.Collections.Generic;
using AjaxPro;

public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Default3));
}
}
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
//返回一个字符串数组
public string[] Data(string prefixText)
{
TZWebSite.ORAConnection ORA = new TZWebSite.ORAConnection();
List<string> OraList = new List<string>();
ArrayList NList = new ArrayList();
string sql = "select TI_NAME from TEAMINFO where TI_NAME like '%" + prefixText + "%'";
using (DataTable dt = ORA.GetTable(sql))
{
foreach (DataRow dr in dt.Rows)
{
//换行
OraList.Add(dr["TI_NAME"].ToString() + "<br>");
}
return OraList.ToArray();
}
}
}



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!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 runat="server">
<title>第3种实现Google的方式</title>

<style type="text/css">
#divText
{
display:none;
position:absolute;
z-index:100;
width:252px;
height:200px;
border:1px solid #6EBDD0;
background-color:#EEF4F7;
}

#txtKeyword
{
width:250px;
border:1px solid #6EBDD0;
}
</style>


<script language="javascript" type="text/javascript">

function displayDiv(id, mode)
{
var divText = document.getElementById("divText");
if (mode)
{
divText.style.display = "inline";
}
else
{
divText.style.display = "none";
}
}

function getText(obj)
{
var keyword = obj.value;
var x = obj.offsetLeft;
var y = obj.offsetTop;

while (obj = obj.offsetParent)
{
x += obj.offsetLeft;
y += obj.offsetTop;
}

if (keyword != "")
{
//这里是我调用的AJAX
//获取的数组,我没有这样写过,但是你怎么不用数组接收呢,我估计:这个方法返回是一个数组,接收的是一个变量,把数组变成变量,以前每个数组的元素自动加上,为分隔符。这样在

var result = new Array();

result= Default3.Data(keyword).value;
var divText = document.getElementById("divText");
//var arr=new Array();

var str="";
if (result != "" && result!=null)
{
//arr=result.split(",");

displayDiv("divText", true);
divText.style.top = (parseInt(y, 10) + 21) + "px";
divText.style.left = x + "px";
// for(var i=0;i<arr.length;i++)
// {
// str+=arr[i];
// }

divText.innerHTML =result;
}
else
{
displayDiv("divText", false);
}
}
}

function setText(obj)
{
//displayDiv("divText", false);
document.getElementById("txtKeyword").value = obj.innerHTML;
}
function setColor(obj)
{
obj.style.backgroundColor = "#D0E4E9";
}
function clearColor(obj)
{
obj.style.backgroundColor = "";
}
</script>

</head>
<body>
<form id="form1" runat="server">
<input id="txtKeyword" type="text" onkeyup="getText(this)" />
<div id="divText" runat="server">
</div>

</form>
</body>
</html>


问题在于
//arr=result.split(",");
无法分解,代码有了,那位大哥告诉我怎样在js获取数组分解字符","














...全文
513 点赞 收藏 回复
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复

还没有回复,快来抢沙发~

发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告