<tr align="middle">
<td> </td>
<td align="left" height="15">房间1</td>
<td align="left"> RMB 567 </td>
<td>无</td>
<td></td>
<td>双床房 </td>
</tr>
<tr align="middle">
<td> </td>
<td align="left" height="15">房间2</td>
<td align="left"> RMB 5671 </td>
<td>无</td>
<td>双床房 </td>
</tr>
</table>
这是一个字符串的内容,我想用asp得到<td></td>里的内容,放到变量里,有什么好办法呢?
a1=房间1
a2=RMB
a3=567
a4=无
a5=双床房
a6=房间2
a7=RMB
a8=5671
a9=无
a10=双床房
15 个解决方案
#1
用正则匹配,然后把值放入数组,再循环输出
#2
我现在能帮你读的到东西。
你看看,再进一步考虑一下应该是可以的
<table>
<tr>
<td>
<span id="sp1">
这里是要收集的信息
</span>
</td>
</tr>
</table>
<input type="button" value="Click me" onClick="vbscript:msgbox '<td>里面的数据是:'&sp1.innerHTML">
你看看,再进一步考虑一下应该是可以的
<table>
<tr>
<td>
<span id="sp1">
这里是要收集的信息
</span>
</td>
</tr>
</table>
<input type="button" value="Click me" onClick="vbscript:msgbox '<td>里面的数据是:'&sp1.innerHTML">
#3
呀,东西居然没帖上来
<table>
<tr>
<td>
<span id="sp1">
这里是要收集的信息
</span>
</td>
</tr>
</table>
<input type="button" value="Click me" onClick="vbscript:msgbox '<td>里面的数据是:'&sp1.innerHTML">
<table>
<tr>
<td>
<span id="sp1">
这里是要收集的信息
</span>
</td>
</tr>
</table>
<input type="button" value="Click me" onClick="vbscript:msgbox '<td>里面的数据是:'&sp1.innerHTML">
#4
页面:
<tr align="middle">
<td> </td>
<td align="left" height="15"><input type="text" name="a1" readonly value="房间1"></td>
<td align="left"><input type="text" name="a2" readonly value="RMB">
<input type="text" name="a3" readonly value="567">
</td>
<td><input type="text" name="a4" readonly value="无"></td>
<td></td>
<td><input type="text" name="a5" readonly value="双床房"></td>
</tr>
<tr align="middle">
<td> </td>
<td align="left" height="15"><input type="text" name="a1" readonly value="房间2"></td>
<td align="left"><input type="text" name="a2" readonly value="RMB">
<input type="text" name="a3" readonly value="5671">
</td>
<td><input type="text" name="a4" readonly value="无"></td>
<td></td>
<td><input type="text" name="a5" readonly value="双床房"></td>
</tr>
提交后再得到数据:
dim a1,a2,a3,a4,a5
a1=request("a1")
a2=request("a2")
a3=request("a3")
a4=request("a4")
a5=request("a5")
a1_t=split(a1,",")
a2_t=split(a2,",")
a3_t=split(a3,",")
a4_t=split(a4,",")
a5_t=split(a5,",")
for i=0 to ubound(a1_t)
response.write "这是第" & i+1 & "条数据:<br>"
response.write "a1=" & a1_t(i) & "<br>"
response.write "a2=" & a1_t(2) & "<br>"
response.write "a3=" & a1_t(3) & "<br>"
response.write "a4=" & a1_t(4) & "<br>"
response.write "a5=" & a1_t(5) & "<br>"
response.write "----------------------<br>"
next
<tr align="middle">
<td> </td>
<td align="left" height="15"><input type="text" name="a1" readonly value="房间1"></td>
<td align="left"><input type="text" name="a2" readonly value="RMB">
<input type="text" name="a3" readonly value="567">
</td>
<td><input type="text" name="a4" readonly value="无"></td>
<td></td>
<td><input type="text" name="a5" readonly value="双床房"></td>
</tr>
<tr align="middle">
<td> </td>
<td align="left" height="15"><input type="text" name="a1" readonly value="房间2"></td>
<td align="left"><input type="text" name="a2" readonly value="RMB">
<input type="text" name="a3" readonly value="5671">
</td>
<td><input type="text" name="a4" readonly value="无"></td>
<td></td>
<td><input type="text" name="a5" readonly value="双床房"></td>
</tr>
提交后再得到数据:
dim a1,a2,a3,a4,a5
a1=request("a1")
a2=request("a2")
a3=request("a3")
a4=request("a4")
a5=request("a5")
a1_t=split(a1,",")
a2_t=split(a2,",")
a3_t=split(a3,",")
a4_t=split(a4,",")
a5_t=split(a5,",")
for i=0 to ubound(a1_t)
response.write "这是第" & i+1 & "条数据:<br>"
response.write "a1=" & a1_t(i) & "<br>"
response.write "a2=" & a1_t(2) & "<br>"
response.write "a3=" & a1_t(3) & "<br>"
response.write "a4=" & a1_t(4) & "<br>"
response.write "a5=" & a1_t(5) & "<br>"
response.write "----------------------<br>"
next
#5
最后应该是:
for i=0 to ubound(a1_t)
response.write "这是第" & i+1 & "条数据:<br>"
response.write "a1=" & a1_t(i) & "<br>"
response.write "a2=" & a2_t(2) & "<br>"
response.write "a3=" & a3_t(3) & "<br>"
response.write "a4=" & a4_t(4) & "<br>"
response.write "a5=" & a5_t(5) & "<br>"
response.write "----------------------<br>"
next
for i=0 to ubound(a1_t)
response.write "这是第" & i+1 & "条数据:<br>"
response.write "a1=" & a1_t(i) & "<br>"
response.write "a2=" & a2_t(2) & "<br>"
response.write "a3=" & a3_t(3) & "<br>"
response.write "a4=" & a4_t(4) & "<br>"
response.write "a5=" & a5_t(5) & "<br>"
response.write "----------------------<br>"
next
#6
以上的说法都是有问题的。上面的都是用Script而不是ASP。而且楼主好像有点概念混淆。ASP是在页面之前执行的,执行过的结果才是看到的页面。如果你要的内容是ASP写出来的话。那就不用这么费事了。但要是读其他的页面话而且不用脚本提交的方法只有在客户端处理后提交,因为Table的内容是不可能被提交的。相关的内容可以参照DHTML
#7
用JavaScript 取value, tr或者td内都可以代一个value取吧, 我估计的。或者找找 tr.text
#8
tr或td里面,你都自定一个value
#9
mark.同意楼上有位兄弟说的,楼主有点概念混淆。你的问题可能是客户端的需要吧。这时就用DHTML来处理吧。如下。
<table class="20" cellspacing="2" width="100%" border="1" id=table1>
<tr align="middle">
<td>12</td>
<td align="left" height="15">房间1</td>
<td align="left">RMB 567 </td>
<td>无</td>
<td>双床房 </td>
</tr>
<tr align="middle">
<td>23</td>
<td align="left" height="15">房间2</td>
<td align="left"> RMB 5671 </td>
<td>无</td>
<td>双床房 </td>
</tr>
</table>
<INPUT type="button" value="Button" onclick="gettds()">
<SCRIPT LANGUAGE=javascript>
<!--
function gettds() {
for (i=0; i < document.all.table1.rows.length; i++) {
for (j=0; j < document.all.table1.rows(i).cells.length; j++) {
alert(document.all.table1.rows(i).cells(j).innerText);
}
}
}
//-->
</SCRIPT>
如果你是想用处理html字符串,则用正则来吧。今天太累了,明天别人还没给出答案的话,我再帮你写。
<table class="20" cellspacing="2" width="100%" border="1" id=table1>
<tr align="middle">
<td>12</td>
<td align="left" height="15">房间1</td>
<td align="left">RMB 567 </td>
<td>无</td>
<td>双床房 </td>
</tr>
<tr align="middle">
<td>23</td>
<td align="left" height="15">房间2</td>
<td align="left"> RMB 5671 </td>
<td>无</td>
<td>双床房 </td>
</tr>
</table>
<INPUT type="button" value="Button" onclick="gettds()">
<SCRIPT LANGUAGE=javascript>
<!--
function gettds() {
for (i=0; i < document.all.table1.rows.length; i++) {
for (j=0; j < document.all.table1.rows(i).cells.length; j++) {
alert(document.all.table1.rows(i).cells(j).innerText);
}
}
}
//-->
</SCRIPT>
如果你是想用处理html字符串,则用正则来吧。今天太累了,明天别人还没给出答案的话,我再帮你写。
#10
这种问题我想应该用客户端 js 来实现比较合理
<table id="test" .......>......</table>
<script language="javascript">
var tb = document.getElementById('tb');
var tds = tb.getElementsByTagName('td');
for (i=0; i<tds.length; i++) {
alert(tds[i].innerHTML);
}
</script>
<table id="test" .......>......</table>
<script language="javascript">
var tb = document.getElementById('tb');
var tds = tb.getElementsByTagName('td');
for (i=0; i<tds.length; i++) {
alert(tds[i].innerHTML);
}
</script>
#11
为什么不用 js,因为,这是从别人网站上通过组件抓过来的内容,保存在字符串上,所以是asp,不是客户端的。
#12
如果要是这样就考虑正则吧
#13
用正则。我这里写的是js,你将你的html字符串帖到textarea里,测试。
如果你想在asp里用的话,对照着js.vbs参考手册翻成vbs的就可以了。
<textarea rows=8 cols=80 id=textarea1>
</textarea>
<script language=javascript>
<!--
function gettd(htmlstr){
var re=/<td(?:\s+\w+=\w+)*>(.*)<\/td>/gim;
while (re.exec(htmlstr) != null) alert(RegExp.$1);
}
</script>
<input type=button onclick="gettd(textarea1.value)" value="getimgsrc">
如果你想在asp里用的话,对照着js.vbs参考手册翻成vbs的就可以了。
<textarea rows=8 cols=80 id=textarea1>
</textarea>
<script language=javascript>
<!--
function gettd(htmlstr){
var re=/<td(?:\s+\w+=\w+)*>(.*)<\/td>/gim;
while (re.exec(htmlstr) != null) alert(RegExp.$1);
}
</script>
<input type=button onclick="gettd(textarea1.value)" value="getimgsrc">
#14
上面写的还有点问题,现在更正了一下,并把vbs的也一并写出来了。
<textarea rows=8 cols=80 id=textarea1>
</textarea>
<script language=javascript>
function gettd_js(htmlstr){//参数是html字符串,返回回车("\r\n")分隔的字符串
str="";
var re=/<td(?:\s+\w+=[^\s]+)*>(.*)<\/td>/gim;
while (re.exec(htmlstr) != null) str+=RegExp.$1+"\r\n";
return str;
}
</script>
<SCRIPT LANGUAGE=vbscript>
Function gettd_vbs(inpStr)
'vbs的版本,可以用在asp里。
Dim oRe, oMatches,str
Set oRe = New RegExp
oRe.Pattern = "<td(?:\s+\w+=[^\s]+)*>(.*)<\/td>"
oRe.IgnoreCase = True
oRe.Global = True
str=""
Set oMatches = oRe.Execute(inpStr)
For i=0 to oMatches.count-1
str=str & oMatches(i).subMatches(0) & vbcrlf
Next
gettd_vbs=str
End Function
</SCRIPT>
<input type=button onclick="alert(gettd_js(textarea1.value))" value="gettd_js">
<input type=button onclick="msgbox(gettd_vbs(textarea1.value))" value="gettd_vbs" language=vbs >
<textarea rows=8 cols=80 id=textarea1>
</textarea>
<script language=javascript>
function gettd_js(htmlstr){//参数是html字符串,返回回车("\r\n")分隔的字符串
str="";
var re=/<td(?:\s+\w+=[^\s]+)*>(.*)<\/td>/gim;
while (re.exec(htmlstr) != null) str+=RegExp.$1+"\r\n";
return str;
}
</script>
<SCRIPT LANGUAGE=vbscript>
Function gettd_vbs(inpStr)
'vbs的版本,可以用在asp里。
Dim oRe, oMatches,str
Set oRe = New RegExp
oRe.Pattern = "<td(?:\s+\w+=[^\s]+)*>(.*)<\/td>"
oRe.IgnoreCase = True
oRe.Global = True
str=""
Set oMatches = oRe.Execute(inpStr)
For i=0 to oMatches.count-1
str=str & oMatches(i).subMatches(0) & vbcrlf
Next
gettd_vbs=str
End Function
</SCRIPT>
<input type=button onclick="alert(gettd_js(textarea1.value))" value="gettd_js">
<input type=button onclick="msgbox(gettd_vbs(textarea1.value))" value="gettd_vbs" language=vbs >
#15
服务端也可以使用正则的
#1
用正则匹配,然后把值放入数组,再循环输出
#2
我现在能帮你读的到东西。
你看看,再进一步考虑一下应该是可以的
<table>
<tr>
<td>
<span id="sp1">
这里是要收集的信息
</span>
</td>
</tr>
</table>
<input type="button" value="Click me" onClick="vbscript:msgbox '<td>里面的数据是:'&sp1.innerHTML">
你看看,再进一步考虑一下应该是可以的
<table>
<tr>
<td>
<span id="sp1">
这里是要收集的信息
</span>
</td>
</tr>
</table>
<input type="button" value="Click me" onClick="vbscript:msgbox '<td>里面的数据是:'&sp1.innerHTML">
#3
呀,东西居然没帖上来
<table>
<tr>
<td>
<span id="sp1">
这里是要收集的信息
</span>
</td>
</tr>
</table>
<input type="button" value="Click me" onClick="vbscript:msgbox '<td>里面的数据是:'&sp1.innerHTML">
<table>
<tr>
<td>
<span id="sp1">
这里是要收集的信息
</span>
</td>
</tr>
</table>
<input type="button" value="Click me" onClick="vbscript:msgbox '<td>里面的数据是:'&sp1.innerHTML">
#4
页面:
<tr align="middle">
<td> </td>
<td align="left" height="15"><input type="text" name="a1" readonly value="房间1"></td>
<td align="left"><input type="text" name="a2" readonly value="RMB">
<input type="text" name="a3" readonly value="567">
</td>
<td><input type="text" name="a4" readonly value="无"></td>
<td></td>
<td><input type="text" name="a5" readonly value="双床房"></td>
</tr>
<tr align="middle">
<td> </td>
<td align="left" height="15"><input type="text" name="a1" readonly value="房间2"></td>
<td align="left"><input type="text" name="a2" readonly value="RMB">
<input type="text" name="a3" readonly value="5671">
</td>
<td><input type="text" name="a4" readonly value="无"></td>
<td></td>
<td><input type="text" name="a5" readonly value="双床房"></td>
</tr>
提交后再得到数据:
dim a1,a2,a3,a4,a5
a1=request("a1")
a2=request("a2")
a3=request("a3")
a4=request("a4")
a5=request("a5")
a1_t=split(a1,",")
a2_t=split(a2,",")
a3_t=split(a3,",")
a4_t=split(a4,",")
a5_t=split(a5,",")
for i=0 to ubound(a1_t)
response.write "这是第" & i+1 & "条数据:<br>"
response.write "a1=" & a1_t(i) & "<br>"
response.write "a2=" & a1_t(2) & "<br>"
response.write "a3=" & a1_t(3) & "<br>"
response.write "a4=" & a1_t(4) & "<br>"
response.write "a5=" & a1_t(5) & "<br>"
response.write "----------------------<br>"
next
<tr align="middle">
<td> </td>
<td align="left" height="15"><input type="text" name="a1" readonly value="房间1"></td>
<td align="left"><input type="text" name="a2" readonly value="RMB">
<input type="text" name="a3" readonly value="567">
</td>
<td><input type="text" name="a4" readonly value="无"></td>
<td></td>
<td><input type="text" name="a5" readonly value="双床房"></td>
</tr>
<tr align="middle">
<td> </td>
<td align="left" height="15"><input type="text" name="a1" readonly value="房间2"></td>
<td align="left"><input type="text" name="a2" readonly value="RMB">
<input type="text" name="a3" readonly value="5671">
</td>
<td><input type="text" name="a4" readonly value="无"></td>
<td></td>
<td><input type="text" name="a5" readonly value="双床房"></td>
</tr>
提交后再得到数据:
dim a1,a2,a3,a4,a5
a1=request("a1")
a2=request("a2")
a3=request("a3")
a4=request("a4")
a5=request("a5")
a1_t=split(a1,",")
a2_t=split(a2,",")
a3_t=split(a3,",")
a4_t=split(a4,",")
a5_t=split(a5,",")
for i=0 to ubound(a1_t)
response.write "这是第" & i+1 & "条数据:<br>"
response.write "a1=" & a1_t(i) & "<br>"
response.write "a2=" & a1_t(2) & "<br>"
response.write "a3=" & a1_t(3) & "<br>"
response.write "a4=" & a1_t(4) & "<br>"
response.write "a5=" & a1_t(5) & "<br>"
response.write "----------------------<br>"
next
#5
最后应该是:
for i=0 to ubound(a1_t)
response.write "这是第" & i+1 & "条数据:<br>"
response.write "a1=" & a1_t(i) & "<br>"
response.write "a2=" & a2_t(2) & "<br>"
response.write "a3=" & a3_t(3) & "<br>"
response.write "a4=" & a4_t(4) & "<br>"
response.write "a5=" & a5_t(5) & "<br>"
response.write "----------------------<br>"
next
for i=0 to ubound(a1_t)
response.write "这是第" & i+1 & "条数据:<br>"
response.write "a1=" & a1_t(i) & "<br>"
response.write "a2=" & a2_t(2) & "<br>"
response.write "a3=" & a3_t(3) & "<br>"
response.write "a4=" & a4_t(4) & "<br>"
response.write "a5=" & a5_t(5) & "<br>"
response.write "----------------------<br>"
next
#6
以上的说法都是有问题的。上面的都是用Script而不是ASP。而且楼主好像有点概念混淆。ASP是在页面之前执行的,执行过的结果才是看到的页面。如果你要的内容是ASP写出来的话。那就不用这么费事了。但要是读其他的页面话而且不用脚本提交的方法只有在客户端处理后提交,因为Table的内容是不可能被提交的。相关的内容可以参照DHTML
#7
用JavaScript 取value, tr或者td内都可以代一个value取吧, 我估计的。或者找找 tr.text
#8
tr或td里面,你都自定一个value
#9
mark.同意楼上有位兄弟说的,楼主有点概念混淆。你的问题可能是客户端的需要吧。这时就用DHTML来处理吧。如下。
<table class="20" cellspacing="2" width="100%" border="1" id=table1>
<tr align="middle">
<td>12</td>
<td align="left" height="15">房间1</td>
<td align="left">RMB 567 </td>
<td>无</td>
<td>双床房 </td>
</tr>
<tr align="middle">
<td>23</td>
<td align="left" height="15">房间2</td>
<td align="left"> RMB 5671 </td>
<td>无</td>
<td>双床房 </td>
</tr>
</table>
<INPUT type="button" value="Button" onclick="gettds()">
<SCRIPT LANGUAGE=javascript>
<!--
function gettds() {
for (i=0; i < document.all.table1.rows.length; i++) {
for (j=0; j < document.all.table1.rows(i).cells.length; j++) {
alert(document.all.table1.rows(i).cells(j).innerText);
}
}
}
//-->
</SCRIPT>
如果你是想用处理html字符串,则用正则来吧。今天太累了,明天别人还没给出答案的话,我再帮你写。
<table class="20" cellspacing="2" width="100%" border="1" id=table1>
<tr align="middle">
<td>12</td>
<td align="left" height="15">房间1</td>
<td align="left">RMB 567 </td>
<td>无</td>
<td>双床房 </td>
</tr>
<tr align="middle">
<td>23</td>
<td align="left" height="15">房间2</td>
<td align="left"> RMB 5671 </td>
<td>无</td>
<td>双床房 </td>
</tr>
</table>
<INPUT type="button" value="Button" onclick="gettds()">
<SCRIPT LANGUAGE=javascript>
<!--
function gettds() {
for (i=0; i < document.all.table1.rows.length; i++) {
for (j=0; j < document.all.table1.rows(i).cells.length; j++) {
alert(document.all.table1.rows(i).cells(j).innerText);
}
}
}
//-->
</SCRIPT>
如果你是想用处理html字符串,则用正则来吧。今天太累了,明天别人还没给出答案的话,我再帮你写。
#10
这种问题我想应该用客户端 js 来实现比较合理
<table id="test" .......>......</table>
<script language="javascript">
var tb = document.getElementById('tb');
var tds = tb.getElementsByTagName('td');
for (i=0; i<tds.length; i++) {
alert(tds[i].innerHTML);
}
</script>
<table id="test" .......>......</table>
<script language="javascript">
var tb = document.getElementById('tb');
var tds = tb.getElementsByTagName('td');
for (i=0; i<tds.length; i++) {
alert(tds[i].innerHTML);
}
</script>
#11
为什么不用 js,因为,这是从别人网站上通过组件抓过来的内容,保存在字符串上,所以是asp,不是客户端的。
#12
如果要是这样就考虑正则吧
#13
用正则。我这里写的是js,你将你的html字符串帖到textarea里,测试。
如果你想在asp里用的话,对照着js.vbs参考手册翻成vbs的就可以了。
<textarea rows=8 cols=80 id=textarea1>
</textarea>
<script language=javascript>
<!--
function gettd(htmlstr){
var re=/<td(?:\s+\w+=\w+)*>(.*)<\/td>/gim;
while (re.exec(htmlstr) != null) alert(RegExp.$1);
}
</script>
<input type=button onclick="gettd(textarea1.value)" value="getimgsrc">
如果你想在asp里用的话,对照着js.vbs参考手册翻成vbs的就可以了。
<textarea rows=8 cols=80 id=textarea1>
</textarea>
<script language=javascript>
<!--
function gettd(htmlstr){
var re=/<td(?:\s+\w+=\w+)*>(.*)<\/td>/gim;
while (re.exec(htmlstr) != null) alert(RegExp.$1);
}
</script>
<input type=button onclick="gettd(textarea1.value)" value="getimgsrc">
#14
上面写的还有点问题,现在更正了一下,并把vbs的也一并写出来了。
<textarea rows=8 cols=80 id=textarea1>
</textarea>
<script language=javascript>
function gettd_js(htmlstr){//参数是html字符串,返回回车("\r\n")分隔的字符串
str="";
var re=/<td(?:\s+\w+=[^\s]+)*>(.*)<\/td>/gim;
while (re.exec(htmlstr) != null) str+=RegExp.$1+"\r\n";
return str;
}
</script>
<SCRIPT LANGUAGE=vbscript>
Function gettd_vbs(inpStr)
'vbs的版本,可以用在asp里。
Dim oRe, oMatches,str
Set oRe = New RegExp
oRe.Pattern = "<td(?:\s+\w+=[^\s]+)*>(.*)<\/td>"
oRe.IgnoreCase = True
oRe.Global = True
str=""
Set oMatches = oRe.Execute(inpStr)
For i=0 to oMatches.count-1
str=str & oMatches(i).subMatches(0) & vbcrlf
Next
gettd_vbs=str
End Function
</SCRIPT>
<input type=button onclick="alert(gettd_js(textarea1.value))" value="gettd_js">
<input type=button onclick="msgbox(gettd_vbs(textarea1.value))" value="gettd_vbs" language=vbs >
<textarea rows=8 cols=80 id=textarea1>
</textarea>
<script language=javascript>
function gettd_js(htmlstr){//参数是html字符串,返回回车("\r\n")分隔的字符串
str="";
var re=/<td(?:\s+\w+=[^\s]+)*>(.*)<\/td>/gim;
while (re.exec(htmlstr) != null) str+=RegExp.$1+"\r\n";
return str;
}
</script>
<SCRIPT LANGUAGE=vbscript>
Function gettd_vbs(inpStr)
'vbs的版本,可以用在asp里。
Dim oRe, oMatches,str
Set oRe = New RegExp
oRe.Pattern = "<td(?:\s+\w+=[^\s]+)*>(.*)<\/td>"
oRe.IgnoreCase = True
oRe.Global = True
str=""
Set oMatches = oRe.Execute(inpStr)
For i=0 to oMatches.count-1
str=str & oMatches(i).subMatches(0) & vbcrlf
Next
gettd_vbs=str
End Function
</SCRIPT>
<input type=button onclick="alert(gettd_js(textarea1.value))" value="gettd_js">
<input type=button onclick="msgbox(gettd_vbs(textarea1.value))" value="gettd_vbs" language=vbs >
#15
服务端也可以使用正则的