我有一个脚本来帮助注释一个图像。我只想在单击按钮时运行此脚本。我尝试使用事件按一下按钮,但它不起作用。这是代码
<head>
<script src="javascripts/jquery.js"></script>
<script src="javascripts/jquery-ui.min.js"></script>
<link rel="stylesheet" href="stylesheets/jquery-ui.css">
////////////// those are the scripts that i use in the function //////
<link rel="stylesheet" href="highlight.js/zenburn.css">
<link rel="stylesheet" href="stylesheets/css/theme-dark/annotorious-dark.css" />
<script src="highlight.js/highlight.pack.js"></script>
<script src="javascripts/annotorious.min.js"></script>
/////////////
<script>
$("#annotation").click(function() {
hljs.initHighlightingOnLoad();
//function of annotation
});
</script>
</head>
<body>
<button type="submit" id="annotation" >
<img src="stylo.png" style="width: 30px ; height:50px" alt="Submit">
</button>
</body>但是这不起作用,当我加载页面时,脚本仍然在运行。当单击“注释”按钮时,我只需要调用它。
发布于 2016-05-23 09:45:22
这就是你要的
<script>
$(document).ready(function(){
$("#annotation").click( function()
{
alert("Hello!");
// hljs.initHighlightingOnLoad(); //function of annotation
});
});
</script>
<button type="submit" id="annotation" > <img src="stylo.png" style="width: 30px ; height:50px" alt="Submit"></button>我不知道您的hljs.initHighlightingOnLoad();函数,但是就按一下按钮执行函数而言,您必须用$(document).ready()函数编写代码。它运行良好,因为我已经用一个警告()进行了测试;
---------------------------UPDATED
我已经使用jquery的cdn和荧光笔来测试它。
<head>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js"></script>
<script>
$(document).ready(function(){
$("#annotation").click( function()
{
hljs.initHighlightingOnLoad(); //function of annotation
});
});
</script>
</head>
<body>
<button type="submit" id="annotation" >
<img src="stylo.png" style="width: 30px ; height:50px" alt="Submit">
</button>
</body>https://stackoverflow.com/questions/37387091
复制相似问题