且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在HREF中放置动态值

更新时间:2022-06-02 00:45:14

Iain说以下是2006年3月11日上午2:49:
Iain said the following on 3/11/2006 2:49 AM:
大家好

我很抱歉,如果这对你们中的一些人来说很简单,但我有
很少有javascript的经验,我无法解决这个问题,

下面的代码是我在网上发现的一个很好的代码片段来旋转一组图像。它工作得很好。


由于你没有发布客户端代码,但是你发布了服务器端代码,所以很难说。

。 br />
但是,我想在HREF中放置一个值,指向当前正在显示的图像的更大版本

示例

显示的图像可能是缩略图tn_image1.jpg
我希望HREF指向图像image1.jpg(图像将始终与缩略图相同但没有tn_前缀)

任何帮助都会感激不尽。


只发布发送到浏览器的HTML。但下面的大部分代码

都是垃圾。

Iain

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++ br /><%@ LANGUAGE =" VBSCRIPT"%>
<%
DIM objFSO,objFile,objFileTextStream,ImageCount
设置objFSO = CreateObject(" Scripting.FileSystemObject" )
LPP = server.MapPath(" teegan.txt")
设置objFile = objFSO.GetFile(LPP)
设置objFileTextStream = objFile.OpenAsTextStream(1)
%&gt ;

< html>
< head>
< script language =" JavaScript">


< script type =" text / javascript">

<! - //隐藏旧浏览器 -


旧浏览器?它们在相当长的一段时间内都不存在,不再试图用b $ b隐藏隐藏。脚本 - 它导致的问题多于它可以解决的问题。

/ *这是一个过渡横幅旋转脚本使用IE过滤器。
Netscape进行简单的图像交换* /


那么Opera,Mozilla,Firefox,Camino,ICEBrowser等等......

var step = 1
var speed = 2 / *改变速度低于(in秒)此值
确定每个横幅在更改之前保留多长时间* /

/ * ==================== =======图片========================= * /
/ *开始编辑这里
* /
/ *来源于
http:// www .havenofbliss.com / javascript / banner.html * /
/ *根据需要添加图片,但记得更新
图片变量* /


任何使您更新numbe的脚本图像的r是一个好兆头

它的垃圾。如果没有别的,让您的服务器端脚本生成

该代码。


/ * =============== =================================== ========== * /

<%
ImageCount = 1

同时objFileTextStream.AtEndOfStream<> True
StrLine = objFileTextStream.ReadLine
如果StrLine<>""然后
%>
var image<%= ImageCount%> = new Image()
image<%= ImageCount%> .src =''<%= trim(StrLine) )%>''
<%
ImageCount = ImageCount + 1
结束如果
循环
objFileTextStream.Close
%>
var number_of_images =<%= ImageCount-1%>
var name_of_image =<%= trim(StrLine)%>

window.onerror = reapply

function reapply()
{
/ *出现错误,重启横幅旋转* /
setTimeout(" slideit()",2000);
返回true;


函数slideit()
{
如果(!document.images)
返回;
if(document.all )
slide.filters.blendTrans.apply();
document.images.slide.src = eva升(QUOT;图像&QUOT; + step +" .src");


上面一行就是这整个脚本垃圾。 eval schmeval,

它的邪恶。


document.images.slide.src = window [''image''+ step +" .src"] ;


if(document.all)
slide.filters.blendTrans.play();
if(step< number_of_images)
step ++;
其他
步骤= 1;
if(document.all)
setTimeout(" slideit()",speed * 1000 + 3000);
else
setTimeout(" slideit()",speed * 1000);
}
< / script>

< title>旋转图像< / title>
< / head>

< body onLoad =" slideit();">
<! - 以下图片代码是占位符横幅
- >
< br>< br>< br>< br>< br>
< center>
< A HREF=我如何导出这个>
Hi All

My apologies if this appears to be simple to some of you but I have
very little experience of javascript and I cannot work this one out,

The code below is a nice piece of code I found on the web to rotate a
set of images. It works very well.
It''s hard to tell since you didn''t post just the client side code but
you posted the server side code as well.
However, I would like to place a value in the HREF which points to a
larger version of the image currently being displayed

Example

The image being displayed may be a thumbnail tn_image1.jpg
I would like the HREF point to the image image1.jpg (the images will
always be the same name as the thumbnails but without the tn_ prefix).

Any help would be gratefully received
Post just the HTML that is sent to the browser. But most of the code
below is trash.
Iain

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++

<%@LANGUAGE="VBSCRIPT"%>
<%
DIM objFSO, objFile, objFileTextStream, ImageCount
Set objFSO = CreateObject("Scripting.FileSystemObject")
LPP=server.MapPath("teegan.txt")
Set objFile = objFSO.GetFile(LPP)
Set objFileTextStream = objFile.OpenAsTextStream(1)
%>

<html>
<head>
<script language="JavaScript">
<script type="text/javascript">
<!-- // Hide from old browsers --
"old browsers"? They haven''t existed in quite some time, stop trying to
"hide" scripts - it causes more problems than it could solve.
/* This is a transition banner rotating script uses IE filters.
Netscape does a simple image swap */
And what about Opera, Mozilla, Firefox, Camino, ICEBrowser, etc...
var step=1
var speed=2 /* change speed below (in seconds) this value
determines how long each banner remains before it is changed */

/* =========================== IMAGES ========================= */
/* Begin Edit Here
*/
/* Source found at
http://www.havenofbliss.com/javascript/banner.html */
/* Add images as needed, but remember to update the number of
images variable */
Any script that makes you update the number of images is a good sign
that its junk. If nothing else, have your server side script generate
that code.

/* ================================================== ========== */

<%
ImageCount=1

Do while objFileTextStream.AtEndOfStream <> True
StrLine=objFileTextStream.ReadLine
if StrLine<>"" then
%>
var image<%=ImageCount%>=new Image()
image<%=ImageCount%>.src=''<%=trim(StrLine)%>''
<%
ImageCount=ImageCount+1
end if
loop
objFileTextStream.Close
%>
var number_of_images = <%=ImageCount-1%>
var name_of_image = <%=trim(StrLine)%>

window.onerror=reapply

function reapply()
{
/* Incase of an error, restart banner rotation */
setTimeout("slideit()",2000);
return true;
}

function slideit()
{
if (!document.images)
return;
if (document.all)
slide.filters.blendTrans.apply();
document.images.slide.src=eval("image" + step + ".src");
Just that one line above makes this entire script junk. eval schmeval,
its evil.

document.images.slide.src = window[''image'' + step + ".src"];

if (document.all)
slide.filters.blendTrans.play();
if (step < number_of_images)
step++;
else
step=1;
if (document.all)
setTimeout("slideit()", speed * 1000 + 3000);
else
setTimeout("slideit()", speed * 1000);
}
</script>

<title>Rotating Images</title>
</head>

<body onLoad="slideit();">
<!-- The following image tag is the place holder for the banner
-->
<br><br><br><br><br>
<center>
<A HREF = HOW DO I DERIVE THIS>




你用代码来推导它,如果你知道如何给你带来怎样的话会更容易发布了实际代码发送到浏览器而不是服务器

边码。甚至更好 - 一个示例页面的URL。


但是,它必须在slideit()函数中完成。


总而言之,它看起来像是一个糟糕的幻灯片放映方式。


-

兰迪

comp.lang .javascript常见问题解答 - http://jibbering.com/faq &新闻组每周

Javascript***实践 - http://www.JavascriptToolbox .com / bestpractices /



You Derive it with code, and it would be a lot easier to tell you how if
you posted the actual code going to the browser instead of the server
side code as well. And even better - a URL to a sample page.

But, it would have to be done in the slideit() function.

All in all, it looks like a crappy way to do a slide show.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


您好Randy


感谢您的投入。

发布的代码是完整的实际工作的asp页面。我b $ b可以接受你的观点,这可能是一种糟糕的做事方式,但是我只是试图找出答案 - 作为一个相对比较好的人b $ b一点点javascript体验 - 如何动态地得出

HREF值的名称。


我一直在玩它但却无法获得该死的

工作的东西,所以我想我会问那些知道即javascript

组的民众喜欢你自己。


我设法找到了很多幻灯片的例子,其中实际上是b
,但我喜欢这个例子的原因是因为它是动态的。

更改外部文本的内容文件,你有一套新的

的幻灯片放映图像。不需要在物理上改变消息来源。


此外,我正在从例子中学习什么是坏事和丑陋

Iain

Hi Randy

Thanks for your input.
The code posted is the complete asp page which does actually work. I
can accept your point that it may be a crappy way to do things but I
was merely attempting to find out - as someone who has relatively
little javascript experience - how to dynamically derive the name of
the HREF value.

I have been playing around with it but just could not get the damn
thing to work so I thought I would ask those who know ie the javascript
group folk like yourself.

I have managed to find quite a few examples of slideshows that actually
work but the reason I liked this example was because it is dynamic.
Change the contents of the external text file and you have a fresh set
of images for the slide show. No need to physically change the source.

In addition, I am learning what is good bad and ugly from the examples
Iain


Iain在3/11/2006 3:52 AM说了以下内容:
Iain said the following on 3/11/2006 3:52 AM:
嗨Randy


嗨Iain,


请引用你要回复的内容。


如果你想通过groups.google.com发布后续内容,请不要不要使用

回复链接在文章的底部。点击显示选项在

文章的顶部,然后点击回复。在

文章标题的底部。

< URL: http://www.safalra.com/special/googlegroupsreply/ >

感谢您的输入。
发布的代码是确实有效的完整asp页面。我可以接受你的观点,这可能是一种糟糕的做事方式,但我只是试图找出 - 作为一个有相对较少的javascript经验的人 - 如何动态地推导出来
HREF值的名称。


将示例URL发布到该ASP代码生成的页面。这使得编写

客户端代码变得更加简单。

我一直在玩它但是却无法得到该死的
工作所以我想我会问那些知道即javascript
群体的人,就像你自己一样。


< a id =" myLink" href =" noScripting.html">


然后在你的函数slideit()中找到这一行:


document.images .slide.src = eval(" image" + step +" .src");


将它更改为我给你的行可能不会起作用它只是一个图像名称 - 一个字符串。


但是,为了改变href,你可以这样做:


document.getElementById(''myLink'')。href = newHREF;


其中newHREF是一个包含大图像href的变量。如何从你的脚本的其他部分获得这些内容取决于 -

直接 - 在你的ASP页面输出的代码上。这就是为什么我要求

来获取示例网址。


你告诉我你的ASP输出是什么,我可以告诉你更好的

脚本,它会做你想要的,更容易。

我设法找到了很多实际工作的幻灯片的例子,但我喜欢这个例子的原因是因为它是动态的。
更改外部文本文件的内容,你有一套新的幻灯片放映图像。不需要实际更改源代码。
Hi Randy
Hi Iain,

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don''t use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
<URL: http://www.safalra.com/special/googlegroupsreply/ >
Thanks for your input.
The code posted is the complete asp page which does actually work. I
can accept your point that it may be a crappy way to do things but I
was merely attempting to find out - as someone who has relatively
little javascript experience - how to dynamically derive the name of
the HREF value.
Post a sample URL to a page generated by that ASP code. It makes writing
client side code a lot simpler.
I have been playing around with it but just could not get the damn
thing to work so I thought I would ask those who know ie the javascript
group folk like yourself.
<a id="myLink" href="noScripting.html">

And then in your function slideit(), find this line:

document.images.slide.src=eval("image" + step + ".src");

Changing it to the line I gave you probably isn''t going to work if its
just an image name - a string.

But, to change the href you do something like this:

document.getElementById(''myLink'').href = newHREF;

Where newHREF is a variable that contains the href to the big image. How
you would go about getting that from the rest of your script depends -
directly - on the code your ASP page is outputting. That is why I asked
for a sample URL.

You show me what your ASP is outputting and I can show you a better
script and it will do what you want, a lot easier.
I have managed to find quite a few examples of slideshows that actually
work but the reason I liked this example was because it is dynamic.
Change the contents of the external text file and you have a fresh set
of images for the slide show. No need to physically change the source.




3年前,我用朋友为PHP写了一个,你甚至没有给
必须给它一个文本文件。它读取目录并获得文件名

本身。所有你需要做的就是放入缩略图和大图像,它剩下的就是



所以,将URL发布到使用的示例页面你的剧本。


-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript***实践 - http://www.JavascriptToolbox .com / bestpractices /



I wrote one in PHP for a friend about 3 years ago that you didn''t even
have to give it a text file. It read the directory and got the filenames
itself. All you had to do was drop in the thumbnail and big image, it
did the rest.

So, post a URL to a sample page that uses your script.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/