我不时地在网页上看到下面的href。然而,我不明白这是要做什么或技术。有人能详细说明吗?
<a href="javascript:;"></a>
我不时地在网页上看到下面的href。然而,我不明白这是要做什么或技术。有人能详细说明吗?
<a href="javascript:;"></a>
当前回答
<a href="javascript:void(0);"></a>
Javascript:告诉浏览器要编写Javascript代码
其他回答
有几种机制可以避免链接到达目的地。题目中的答案不是很直观。
一个更清晰的选项是使用href="#no",其中#no是文档中未定义的锚。
您可以使用更语义化的名称,如#disable或#action来增加可读性。
该方法的好处:
避免空href="#"的"移到顶部"效果 避免使用javascript
缺点:
必须确保在文档中没有使用锚名。 URL更改为将(不存在的)锚包含为片段,并创建一个新的浏览器历史记录条目。这意味着在点击链接后点击“返回”按钮不会像预期的那样运行。
由于<a>元素不充当链接,在这些情况下,最好的选择不是使用<a>元素,而是使用<div>并提供所需的链接样式。
基本上不是使用链接来移动页面(或锚点),使用这个方法启动一个javascript函数。
<script>
function doSomething() {
alert("hello")
}
</script>
<a href="javascript:doSomething();">click me</a>
单击该链接将触发警报。
<a href="javascript:alert('Hello');"></a>
是:
<a href="" onclick="alert('Hello'); return false;"></a>
1. Use that java script to Clear an HTML row Or Delete a row using the id set to a span and use JQuery to set a function to that span's click event.
2. Dynamically set the div html to a string variable and replace {id} with a 1 or 2 etc. cell of a larger div table and rows
<div class="table-cell">
<span id="clearRow{id}">
<a href="javascript:" style-"color:#c32029; align:right; font-size:8pt;">Clear</a>
</span>
</div>
<div class="table-cell">
<span id="deleteRow{id}">
<a href="javascript:" style-"color:#c32029; align:right; font-size:8pt;">Delete</a>
</span>
</div>
//JQuery - Clear row
$("#clearRow" + idNum).click(function(){
$("someIDOrWildcardSelector" + idNum).val("");
$("someIDOrWildcardSelector" + idNum).val("");
$("someIDOrWildcardSelector" + idNum).val("");
});
//JQuery to remove / delete an html row
$("#deleteRow" + idNum).click(function(){
//depending upon levels of parent / child use 1 to many .parent().parent().parent()
$(this).parent().remove();
});
请参考:
<a href="Http://WWW.stackoverflow.com">Link to the website opened in different tab</a>
<a href="#MyDive">Link to the div in the page(look at the chaneged url)</a>
<a href="javascript:;">Nothing happens if there is no javaScript to render</a>