href属性中的JavaScript函数调用
我试图通过href属性中的JavaScript函数调用,javascript,jquery,html,twitter-bootstrap-3,bootstrap-modal,Javascript,Jquery,Html,Twitter Bootstrap 3,Bootstrap Modal,我试图通过标记中的href属性调用基本javascript函数。我以前做过无数次,但现在每个浏览器都在jQuery中对href javascript调用抛出异常,一些浏览器选择不运行它,而是打开一个空白的新窗口。在这一点上,我只是有目的。有什么想法吗 HTML: <td> <a href="javascript:showQuote(12);" data-toggle='modal' target='#quoteBox'> View Quote
标记中的href属性调用基本javascript函数。我以前做过无数次,但现在每个浏览器都在jQuery中对href javascript调用抛出异常,一些浏览器选择不运行它,而是打开一个空白的新窗口。在这一点上,我只是有目的。有什么想法吗
HTML:
<td>
<a href="javascript:showQuote(12);" data-toggle='modal' target='#quoteBox'>
View Quote
</a>
</td>
function showQuote(id){
$("#spot").load("viewQuote.php?id=" + id);
$('#modal').modal('show');
}
Chrome是唯一一个这样做的浏览器(它仍然会抛出一个错误)。我已经通过一些在线验证器进行了验证,结果证明它们是干净的
另外,我使用的是jQuery版本1.11.3。最好用“jQuery”风格编写 更新答案-使用当前控件id
<td>
<a href="" data-toggle='modal' id="12" class="mylink" target='#quoteBox'>
View Quote
</a>
</td>
最好用“jquery”风格编写 更新答案-使用当前控件id
<td>
<a href="" data-toggle='modal' id="12" class="mylink" target='#quoteBox'>
View Quote
</a>
</td>
HTML
HTML
这是一种非常糟糕的做法:为什么不添加一个触发函数的
onclick
事件,而不是将其设置为href值?如果按照Nick Z的建议使用onclick,请通过JS或jQuery$('something')附加它。单击(…)
不是通过在程序员的中放置onclick=来实现的。您会得到什么错误?@stephenciofi将数据id=“12”
添加到元素中,并使用$(this).data(“id”)
在通用事件侦听器中。这是一种非常糟糕的做法:为什么不添加触发函数的onclick
事件,而不是将其设为href值?如果按照Nick Z的建议使用onclick,请通过JS或jQuery$('something')附加它。单击(…)
不是通过在程序员的中放置onclick=来实现的。您得到了什么错误?@stephenciofi将数据id=“12”
添加到元素中,并在通用事件侦听器中使用$(this).data(“id”)
。
<td><a href="javascript:showQuote(12,event);" data-toggle='modal' target='#quoteBox'>View Quote</a></td>
function showQuote(id,event){
$("#spot").load("viewQuote.php?id=" + id);
$('#modal').modal('show');
event.preventDefault();
return false;
}