ASP函数可以使用数字确定,但不能使用字符串 [英] ASP Function OK with Numeric but Fails with String

查看:89
本文介绍了ASP函数可以使用数字确定,但不能使用字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个ASP页面,需要使用javascript来运行IE插件,并且我有从服务器上的数据库读取的vbscript.在javascript部分,我有一个函数,该函数由我在vbscript部分中建立的HTML链接调用.最终结果是,页面加载后,用户可以单击多个链接,从而影响IE插件.

问题:如果我仅发送数字数据,则构建的HTML链接可以正常工作,但是我也有一个字符串(从数据库读取的名称)也想应用于发送到javascript部分.我从代码中删除了IE插件,因此我可以找出问题所在,但无法提出解决方案.所以问题是,如何将字符串放入javascript函数?代码如下:

函数setLocation(lat,lon,id){
lat = Number(lat);
lon = Number(lon);
id =数字(id);
//id = String(id);
...
}

在vbscript部分中,以下函数将调用此函数:

< code> ''好东西
''response.write(< a href =""&#"&""onClick ="&" setLocation(& rLat&",& rLong&" )"&">& rID&"</a>)


"试图将rID纳入例程
response.write(< a href =""&#"&""onClick ="&" setLocation(& rLat&" ,,& rLong&," & rID&)""&>"& rID&</a>")</code>

...假设显示正确,则从数据库读取的值为rLat,rLong和rID. rID是字符串.现在,当我运行此命令时,链接显示正常,并在链接中显示rID(名称).如果我使用数字值作为ID,则第一个可以正常运行,第二个可以正常运行.它失败,并带有以下消息的字符串(例如,数据库中的值为Freddy):

"Freddy"未定义

因此,它采用变量内容而不是变量名称. ???
这可能很容易,但是我还没有弄清楚.

Hello All,

I have an ASP page that requires javascript to run an IE plug-in, and I have vbscript that reads from a database on the server. In the javascript section I have a function that''s called by an HTML link that I build up in the vbscript section. The end result is that after the page loads the user has multiple links they can click on that affect the IE plug-in.

The problem: the built HTML links work fine if I only send numeric data, but I have a string (the name read from the database) that I would like to apply to send to the javascript section as well. I eliminated the IE plug-in from the code so I could isolate the problem but I haven''t been able to come up with a solution. So the question is, how do I get my string into the javascript function? Here''s the code:

function setLocation(lat, lon, id) {
lat = Number(lat);
lon = Number(lon);
id = Number(id);
//id = String(id);
...
}

and this function is called by the following in the vbscript section:

<code> ''good stuff
''response.write ("<a href=""" & "#" & """ onClick=" & """setLocation(" & rLat & "," & rLong & ")""" & ">" & rID & "</a>")


''trying to get the rID up into the routine
response.write ("<a href=""" & "#" & """ onClick=" & """setLocation(" & rLat & "," & rLong & "," & rID & ")""" & ">" & rID & "</a>") </code>

... assuming that shows up correctly, the values read from the database are rLat, rLong, and rID. rID is the string. Now when I run this, the link shows up fine and shows the rID (name) in the link. The first one does fine, and the second one runs fine if I use a numeric value as the ID. It fails with a string (say the value in the database is Freddy) with the following message:

''Freddy'' is undefined

So it''s taking the variable contents rather than the variable name. ???
This is probably easy but I haven''t figured it out.

推荐答案

有您的答案.您应该使用''字符作为字符串.
setLocation(& rLat&",& rLong&","& rID&")
There is ur answer. you should use '' character for strings.
setLocation(" & rLat & "," & rLong & ",''" & rID & "'')


这篇关于ASP函数可以使用数字确定,但不能使用字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆