日安,
我有一个超链接
Click in this ¿ <a href="#" id="hr" class="alert-link"><strong>Link</strong> ?</a>我想使用一个bootstrap alert,OnClick使用了一个Javascript函数。我该怎么做呢?
我试着做这样的事情,但它不起作用。
Click in this ¿ <a href="#" OnClick="myfuncti()"id="hr" class="alert-link"><strong>Link</strong> ?</a>谢谢。
发布于 2018-08-20 12:04:36
您想要做的是,如果您想要一个函数,添加以下onclick属性:
<a href="#" onclick="function()" id="hr" class="alert-link"><strong>Link</strong> ?</a>还要确保您的JS和HTML文件被正确链接,并且您的函数名与您要调用的函数名匹配。
发布于 2018-08-20 12:07:56
试试这段代码
function myfunction(){
//do what you want...
}<a href="#" id="hr" class="alert-link" onclick="myfunction()"><strong>Link</strong> ?</a>
发布于 2018-08-20 13:49:17
锚标签本身有一个动作,所以你的回调函数应该有一个preventDefault方法才能工作。
例如,用于
<a href="#" onclick="foo()" id="hr" class="alert-link"><strong>Link</strong> ?</a>
function foo() {
event.preventDefault();
}
function foo() {
event.preventDefault();
console.log("hello")
} <a href="#" onclick="foo()" id="hr" class="alert-link"><strong>Link</strong> ?</a>
https://stackoverflow.com/questions/51923971
复制相似问题