我正在制作一个网站,其中有几个按钮。由于某些我无法弄清楚的原因,这些在最后一两天停止了工作。
这是点击功能。
//Click "Belgium"
$('#actions').on('click', '#btnBelgium', function ()
{
console.log("belgium pressed");
clearTableRows();
irelandMatches.length = 0;
nation = "belgium";
loadDoc();
document.getElementById("btnSort").value = "Sort: Descending";
matchOrderReversed = false;
});
这是HTML:
<div id="actions">
<input type="submit" class="navButton" value="Sort: Descending" id="btnSort">
<input type="submit" class="navButton" value="" id="btnBelgium">
<input type="submit" class="navButton" value="" id="btnIreland">
<input type="submit" class="navButton" value="" id="btnItaly">
<input type="submit" class="navButton" value="" id="btnSweden">
</div>
Javascript的整个部分页面包含在:
中$(document).ready(function ()
答案 0 :(得分:1)
你为什么不用?
$('#btnBelgium').bind('click', function ()
{
console.log("belgium pressed");
clearTableRows();
irelandMatches.length = 0;
nation = "belgium";
loadDoc();
document.getElementById("btnSort").value = "Sort: Descending";
matchOrderReversed = false;
});
答案 1 :(得分:1)
您提供的代码片段有效。如果触发按钮则单击检查开发工具中js控制台中是否有任何错误。还应该有其他问题。
//Click "Belgium"
$('#actions').on('click', '#btnBelgium', function ()
{
console.log("belgium pressed");
alert('clicked');
clearTableRows();
irelandMatches.length = 0;
nation = "belgium";
loadDoc();
document.getElementById("btnSort").value = "Sort: Descending";
matchOrderReversed = false;
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="actions">
<input type="submit" class="navButton" value="Sort: Descending" id="btnSort">
<input type="submit" class="navButton" value="" id="btnBelgium">
<input type="submit" class="navButton" value="" id="btnIreland">
<input type="submit" class="navButton" value="" id="btnItaly">
<input type="submit" class="navButton" value="" id="btnSweden">
</div>
&#13;