Html <a href="#" class="view"> 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3160758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does <a href="#" class="view"> mean?
提问by sharath
In my html page, I see a link whose 'view source' code is as below :
在我的 html 页面中,我看到一个链接,其“查看源代码”代码如下:
<a href="#" class="view">
I see a valid link when I hover my mouse on it and when I click it, it works. But I am not able to find where and how this URL gets generated. I found the class a.view being defined in one of the CSS, but couldn't find the URL in the page source.. Can somebody help me out on whr i can find this URL ?
当我将鼠标悬停在它上面时,我看到一个有效的链接,当我单击它时,它可以工作。但我无法找到生成此 URL 的位置和方式。我发现在其中一个 CSS 中定义了 a.view 类,但在页面源代码中找不到 URL .. 有人可以帮我找到这个 URL 吗?
回答by Mattis
I felt like replying as well, explaining the same thing as the others a bit differently. I am sure you know most of this, but it might help someone else.
我也想回答,对同一件事的解释与其他人略有不同。我相信你知道大部分内容,但它可能会帮助其他人。
<a href="#" class="view">
The
这
href="#"
part is a commonly used way to make sure the link doesn't lead anywhere on it's own. the #-attribute is used to create a link to some other section in the same document. For example clicking a link of this kind:
part 是一种常用的方法,用于确保链接不会自行引导到任何地方。#-attribute 用于创建指向同一文档中其他部分的链接。例如,单击此类链接:
<a href="#news">Go to news</a>
will take you to wherever you have the
将带你到任何你有
<a name="news"></a>
code. So if you specify # without any name like in your case, the link leads nowhere.
代码。因此,如果您指定 # 没有任何名称,就像您的情况一样,链接将无处可去。
The
这
class="view"
part gives it an identifier that CSS or javascript can use. Inside the CSS-files (if you have any) you will find specific styling procedures on all the elements tagged with the "view"-class.
部分为其提供了一个 CSS 或 javascript 可以使用的标识符。在 CSS 文件(如果有的话)中,您会在所有标记为“视图”类的元素上找到特定的样式程序。
To find out where the URL is specified I would look in the javascript code. It is either written directly in the same document or included from another file.
要找出指定 URL 的位置,我会查看javascript 代码。它要么直接写在同一文档中,要么包含在另一个文件中。
Search your source code for something like:
搜索您的源代码,例如:
<script type="text/javascript"> bla bla bla </script>
or
或者
<script> bla bla bla </script>
and then search for any reference to your "view"-class. An included javascript file can look something like this:
然后搜索对“视图”类的任何引用。包含的 javascript 文件可能如下所示:
<script type="text/javascript" src="include/javascript.js"></script>
In that case, open javascript.js under the "include" folder and search in that file. Most commonly the includes are placed between <head>
and </head>
or close to the </body>
-tag.
在这种情况下,打开“include”文件夹下的 javascript.js 并在该文件中搜索。最常见的是包括被放置之间<head>
和</head>
或接近</body>
-标签。
A faster way to find the link is to search for the actual link it goes to. For example, if you are directed to http://www.google.com/search?q=htmlwhen you click it, search for "google.com" or something in all the files you have in your web project, just remember the included files.
查找链接的更快方法是搜索它所指向的实际链接。例如,如果您在点击http://www.google.com/search?q=html时被定向到http://www.google.com/search?q=html,请在您的网络项目中的所有文件中搜索“google.com”或其他内容,请记住包含的文件。
In many text editors you can open all the files at once, and then search in them all for something.
在许多文本编辑器中,您可以一次打开所有文件,然后在其中搜索所有文件。
回答by Darin Dimitrov
回答by STW
Javascript may be hooking up to the click-event of the anchor, rather than injecting any href.
Javascript 可能会连接到锚点的点击事件,而不是注入任何 href。
For example, jQuery:
例如,jQuery:
$('a.view').click(function() { Alert('anchor without a href was clicked');});
Of course, the javascript can do anything it wants with the click event--such as navigate to some other page (in which case the href is never set, but the anchor still behaves as though it were)
当然,javascript 可以对 click 事件做任何它想做的事情——比如导航到其他页面(在这种情况下,href 从未设置,但锚点仍然表现得好像它是)
回答by Justin Niessner
Don't forget to look at the Javascript as well. My guess is that there is custom Javascript code getting executed when you click on the link and it's that Javascript that is generating the URL and navigating to it.
不要忘记查看 Javascript。我的猜测是,当您单击链接时会执行自定义 Javascript 代码,正是该 Javascript 生成 URL 并导航到它。
回答by Jouke van der Maas
It probably works with Javascript. When you click the link, nothing happens because it points to the current site. The javascript will then load a window or an url. It's used a lot in AJAX web apps.
它可能适用于 Javascript。当您单击该链接时,没有任何反应,因为它指向当前站点。然后 javascript 将加载一个窗口或一个 url。它在 AJAX 网络应用程序中被大量使用。