混合使用javascript,image和href [英] Mix of javascript, image and href

查看:61
本文介绍了混合使用javascript,image和href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有clickevent的asp.net图像按钮。

我在图像周围附加了一个锚点和一个小文本。

如果我点击图像事件执行(当锚点的href

显示在状态栏中)


如果用户点击图像或文本beneat它应该做同样的,

执行图像asp.net服务器事件。


我可以使用javascript管理这个,但是href必须包含

字符来获取鼠标。

我使用#但是窗口滚动到顶部,回发发生并且滚动

位置仍然位于顶部。

我使用它们在我的母版页中维护滚动内容。


我可以使用两个控件,一个图像按钮和一个链接按钮,我试图

避免第二个。


我的想法是,我可能会使用一个div,这样整个区域的行为就像点击一样......''thingy''..


有什么想法吗?

I have an asp.net imagebutton with a clickevent.
I have enclosed an anchor around the image and a small text.
If i click the image the event is executed (while the href of the anchor
shows in the statusbar)

If the user clicks the image or the text beneat it it should do the same,
executing the image asp.net server event.

I can manage this fine using javascript but the href must contain a
character to get the mousehand.
I used # but than the window scrolls to top, postback happens and the scroll
position remains to top.
I use them maintain scroll stuff in my masterpage.

I could use two controls, an imagebutton and a linkbutton, i was trying to
avoid the 2nd.

The idea is that i ever might use a div so that the whole area behaves as
one click.. ''thingy''..

Any ideas?

推荐答案




Edwin Knoppert写道:
Hi,

Edwin Knoppert wrote:

我有一个带有clickevent的asp.net图像按钮。

我在图像周围附上了一个锚点和一个小文本。

如果我点击图像,事件就会被执行(而锚点的href

显示在状态栏中)

如果用户点击图像或文本beneat它应该做同样的,

执行图像asp.net服务器事件。


我可以使用javascript管理这个很好但是href必须包含一个

字符到得到mousehand。

我使用#但是窗口滚动到顶部,回发发生并且滚动

位置仍然是顶部。
I have an asp.net imagebutton with a clickevent.
I have enclosed an anchor around the image and a small text.
If i click the image the event is executed (while the href of the anchor
shows in the statusbar)

If the user clicks the image or the text beneat it it should do the same,
executing the image asp.net server event.

I can manage this fine using javascript but the href must contain a
character to get the mousehand.
I used # but than the window scrolls to top, postback happens and the scroll
position remains to top.



您必须在事件处理程序中返回false以避免执行HREF。


此外,最佳做法是不要使用#在HREF中,而是

a链接到一个页面,解释了为什么这个功能没有

JavaScript,或者链接到显示相同内容的基本页面,但是<没有JavaScript提供的额外功能的



示例:

< a href =" nojs.html" onclick =" myFunction(); return false;">

< img src =" ..." />< / a>


HTH,

Laurent

-

Laurent Bugnion,GalaSoft

软件工程: http://www.galasoft- LB.ch

私人/马来西亚: http:/ /mypage.bluewin.ch/lbugnion

支持加尔各答的儿童: http://www.calcutta-espoir.ch

You must return false in the event handler to avoid executing the HREF.

Additionally, the best practice is not to use "#" in the HREF but rather
a link to a page explaining why this functionality doesn''t work without
JavaScript, or linking to a basic page showing the same content, but
without the additional functionality provided by JavaScript.

Example:
<a href="nojs.html" onclick="myFunction();return false;">
<img src="..." /></a>

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch


在这种情况下,它是带有事件的asp网络图像。

锚点执行js代码并显示一个alert(),之后滚动

发生,即使返回0(也许这应该是''false'')然后

执行imagebutton事件并忽略返回。
In this case it''s a asp net image with event.
The anchor executes the js code and shows an alert(), after that the scroll
happens, even with return 0 (maybe this should be ''false'') but then the
imagebutton event is executed and the return is ignored.

JavaScript,或链接到显示相同内容的基本页面,但
JavaScript, or linking to a basic page showing the same content, but



哦,也许是一个不存在的页面..


" Laurent Bugnion" < ga ********* @ bluewin.chschreef in bericht

news:ua ************** @ TK2MSFTNGP03.phx.gbl。 ..

O well , maybe a non existing page..

"Laurent Bugnion" <ga*********@bluewin.chschreef in bericht
news:ua**************@TK2MSFTNGP03.phx.gbl...





Edwin Knoppert写道:
Hi,

Edwin Knoppert wrote:

>我有一个带有clickevent的asp.net图像按钮。
我在图像周围附加了一个锚点和一个小文本。
如果我点击图像,事件就会被执行(而href of

如果用户单击图像或文本,它应该执行相同的操作,执行图像asp.net服务器事件。

我可以使用javascript管理这个很好但是href必须包含一个
字符来获取鼠标。
我使用#但是窗口滚动到顶部,回发发生并且<滚动位置保持在顶部。
>I have an asp.net imagebutton with a clickevent.
I have enclosed an anchor around the image and a small text.
If i click the image the event is executed (while the href of the anchor
shows in the statusbar)

If the user clicks the image or the text beneat it it should do the same,
executing the image asp.net server event.

I can manage this fine using javascript but the href must contain a
character to get the mousehand.
I used # but than the window scrolls to top, postback happens and the
scroll position remains to top.



您必须在事件处理程序中返回false以避免执行HREF。


此外,最佳做法不是使用#在HREF中,而是一个

链接到一个页面,解释为什么没有

JavaScript,或链接到显示相同内容的基本页面,此功能不起作用,但

没有JavaScript提供的额外功能。


示例:

< a href =" nojs.html" onclick =" myFunction(); return false;">

< img src =" ..." />< / a>


HTH,

Laurent

-

Laurent Bugnion,GalaSoft

软件工程: http://www.galasoft- LB.ch

私人/马来西亚: http:/ /mypage.bluewin.ch/lbugnion

支持加尔各答的儿童: http://www.calcutta-espoir.ch






Edwin Knoppert写道:
Hi,

Edwin Knoppert wrote:

在这种情况下,它是带有事件的asp网络图像。

锚执行js代码并显示一个alert(),之后滚动

发生,即使返回0(也许这应该是''false'')然后执行

imagebutton事件并且返回被忽略。
In this case it''s a asp net image with event.
The anchor executes the js code and shows an alert(), after that the scroll
happens, even with return 0 (maybe this should be ''false'') but then the
imagebutton event is executed and the return is ignored.



生成的HTML代码是什么?它是一个输入类型='''图像'',还是像我描述的那样的

普通图像?


滚动到机顶"效果是典型的具有#的效果。在HREF中。什么

发生的是,浏览器会查找名为"的锚点。 (空的

字符串)在页面中(就像它会找到一个名为hello的锚点}

如果你有href =''#hello'' ),因为它没有找到任何东西,它会跳到页面顶部的
。通常的解决方法是增加返回假;要点击onclick事件
,所以你必须找到一种方法来获取ASP.NET引擎

来输出这段代码。也许使用Image

类的Attributes集合,你可以让它添加return false;声明。

What is the produced HTML code? Is it a "input type=''image''", or a
normal image like I described?

The "scroll-to-top" effect is typical of having "#" in the HREF. What
happens there is that the browser looks for the anchor named "" (empty
string) in the page (just like it would look for an anchor named "hello"
if you had "href=''#hello''"), and since it doesn''t find any, it jumps to
the top of the page. The usual cure for that is to add return false; to
the onclick event, so you have to find a way to get the ASP.NET engine
to output this code. Maybe using the Attributes collection of the Image
class, you can get it to add the "return false;" statement.


> JavaScript,或链接到显示相同内容的基本页面,但
>JavaScript, or linking to a basic page showing the same content, but



好​​吧,也许是一个不存在的页面..

O well , maybe a non existing page..



不确定你的意思。


HTH,
Laurent

-

Laurent Bugnion,GalaSoft

软件工程: http://www.galasoft-LB.ch

私人/马来西亚: http://mypage.bluewin.ch/lbugnion

支持加尔各答的儿童: http://www.calcutta-espoir.ch

Not sure what you mean.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch


这篇关于混合使用javascript,image和href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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