因结太快,而问题还是没有解决。如何判断值是否存在数组????

life360 2004-11-02 04:35:07
1.htm

<form name="form1" method="post" action="e.asp">
<input type="checkbox" name="ab" value="1">
<input type="checkbox" name="ab" value="2">
<input type="checkbox" name="ab" value="3">
<input type="checkbox" name="ab" value="4">
<input type="checkbox" name="ab" value="5">
<input type="submit" name="Submit" value="Submit">
</form>


请问如何 判断 a 是否 在 ab 里面



e.asp


<%
ab =request("ab")
a =2 \\或别的数字

If Then \\怎么写呢???

Response.Write("存在")
Else
Response.Write("不存在")
End If


%>



原来的问题
http://community.csdn.net/Expert/topic/3514/3514679.xml?temp=.9488947

http://community.csdn.net/Expert/topic/3513/3513881.xml?temp=.4926569

以上的回答是有bug 的

<%
ab = request("ab")
a = 1
if instr(1,ab,a)>0 then
response.write "存在"
else
response.write "不存在"
end if
%>

若 e.asp?ab=3&ab=4&ab=5&ab=11111111

也会提示 存在的

...全文
197 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
life360 2004-11-03
  • 打赏
  • 举报
回复
问题解决了。谢谢各位

正确的写法是


<%
for each a in request("ab")
if a=3 then
response.write "存在"
end if
next
%>



cocoismywife 2004-11-02
  • 打赏
  • 举报
回复
<%
'on error resume next
dim a,b,c,i,s
c=0
s=0
for each temp in request("ab")
c=c+1
next
redim a(c)
for i= 1 to ubound(a)
select case request("ab")(i)
case "1"
s=s+1
end select
response.write "<br/>"
next
if s>=1 then
response.write "存在"
else
response.write "不存在"
end if
%>
这样不就好了,不知道楼猪怎么想的
gaojie001 2004-11-02
  • 打赏
  • 举报
回复
aa=request.form("aa")
for each bb in aa
a=1
if a=bb then response.write "存在"
next
soft_2008 2004-11-02
  • 打赏
  • 举报
回复

按楼主的意思是:某个元素a是否存在数组ab中?是这个意思吗?如果是这样子,那不是用一个循环在里与各个元素逐一比较,找到或到数组尾就跳出该循环,不就解决问题了吗?
cdsun 2004-11-02
  • 打赏
  • 举报
回复
你不是就要判断是否包含1吗?

还有什么功能?

我的代码我测试了的阿
没有错误阿
tianch 2004-11-02
  • 打赏
  • 举报
回复
<%
ab ="," & request("ab") & ","
a =2 \\或别的数字

If inStr(ab,"," & a & ",")=-1 Then \\怎么写呢???

Response.Write("存在")
Else
Response.Write("不存在")
End If


%>
判断有错,等于-1表示没找到
EasonHoi 2004-11-02
  • 打赏
  • 举报
回复
isarray();
lhzongji 2004-11-02
  • 打赏
  • 举报
回复
晕,
a=1
if instr(1,"," & "1,2,3,4,5" & "," , "," & a & ",") then response.write "存在"
life360 2004-11-02
  • 打赏
  • 举报
回复
也是说,我只需要 验证 a 是否存在 ab 里面

也是是只有一个“存在” 或“不存在”

楼上的是可以实现 bug 但不是 循环输出
sbkyv 2004-11-02
  • 打赏
  • 举报
回复
不想去想什么方法拉!就给你个怪异的。
用两个,来判断是不是字符串的开头或结尾
<
%
ab =","&request("ab")&","
a =2

If instr(ab,","&a&",")>0 then Then

Response.Write("存在")
Else
Response.Write("不存在")
End If


%>
life360 2004-11-02
  • 打赏
  • 举报
回复
楼上的,我只需要一个提示,而不是循环输出
lhzongji 2004-11-02
  • 打赏
  • 举报
回复
<%
tmpChar="1,2,3,4,5"
a=111111
for i=0 to ubound(split(tmpChar,","))
if instr(1,split(tmpChar,",")(i),a) then
response.write "存在!"
else
response.write "不存在!"
end if
next
%>

_________________________________________________
结果:
不存在!不存在!不存在!不存在!不存在!




我真是不懂楼主想要什么。验证一个?是什么意思,难道你给出11111,数组里面只要有一个1就可以满足这个条件???
life360 2004-11-02
  • 打赏
  • 举报
回复
若是别的值呢,你都没有考虑过别的参数, 用样若 a=5 呢???
cocoismywife 2004-11-02
  • 打赏
  • 举报
回复
我这个应该可以,注意我的case是1,不是2
cocoismywife 2004-11-02
  • 打赏
  • 举报
回复
<%
'on error resume next
dim a,b,c,i
for each temp in request("ab")
c=c+1
next
redim a(c)
for i= 1 to ubound(a)
select case request("ab")(i)
case "1"
response.write "存在"
case else
response.write "不存在"
end select
response.write "<br>"
next
%>
life360 2004-11-02
  • 打赏
  • 举报
回复
楼上的一样的 ,

<%
a=1
for i=0 to ubound(split(request("ab"),","))
if instr(1,split(request("ab"),",")(i),a) then
response.write "存在!"
else
response.write "不存在!"
end if
next
%>

你输入 a=111111

并是循环输出了。我只需要验证一个数值
超级大笨狼 2004-11-02
  • 打赏
  • 举报
回复
前台页面page1.html:

<FORM action="Page2.asp" method=POST id="form1">
<table id="myTable">
<tr >
<td id="myTd1">
<INPUT type="text" name="text1">内容
</td>
</tr>
</table>
<br/>
<button onclick="doAdd();" >AddRow</button>
<button onclick="doDel();" >DelRow</button>
<button onclick="form1.submit();">OK!</button>
</FORM>

<script>
var i=0;
function doAdd()
{
i=i+1;
var nowTable=document.all.myTable;
var newTr=nowTable.insertRow(i);
var newTd=newTr.insertCell(0);
newTd.innerHTML =myTd1.innerHTML;

//假设名字是随便取的
newTd.getElementsByTagName("INPUT")[0].setAttribute("name","text" + parseInt( Math.random() * 100));

//可以用下面这行测试新名字
alert( newTd.getElementsByTagName("INPUT")[0].getAttribute("name"));
//getAttribute("name"));

}
function doDel()
{
if(i>=1)
{
document.all.myTable.rows(i).removeNode();
i=i-1;
}
else
{
alert("不能全删光!");
}
}
</script>

后台页面page2.asp:

<%

for each myInput in Request.Form
Response.Write myInput
Response.Write "="
Response.Write Request(myInput)
Response.Write "<br/>"
next
%>








<table id="idTB" border=1>
<tr id="idTR">
<td>First row</td>
</tr>
</table>
<input type="button" onclick="addRow();" value="加一行">
<br/>
<input type="button" onclick="RemoveRow();" value="减一行">
<script language="javascript">
function addRow()
{
oTR=idTB.insertRow(idTB.rows.length);
oTD=oTR.insertCell(0);
oTD.innerText="New Row " + oTR.rowIndex;
}
function RemoveRow()
{
oTR=idTB.rows(idTB.rows.length-1);
oTR.removeNode(true);
}
</script>
lhzongji 2004-11-02
  • 打赏
  • 举报
回复
我没听清楚你这种存在是没个数组元素包含还是相等与a
如果是相等于a应该这样
for i=0 to ubound(split(request("ab"),","))
if split(request("ab"),",")(i)=a then
response.write "存在!"
else
response.write "不存在!"
end if
next
lhzongji 2004-11-02
  • 打赏
  • 举报
回复
for i=0 to ubound(split(request("ab"),","))
if instr(1,split(request("ab"),",")(i),a) then
response.write "存在!"
else
response.write "不存在!"
end if
next
life360 2004-11-02
  • 打赏
  • 举报
回复
以上的


若你输入

a=1111

一样说存在的

a=123

一样存在的
加载更多回复(10)

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧