使用谷歌代码Pretify回调
Using callbacks with Google Code Prettify
我在页面上使用谷歌代码pretify(工作正常(,我想添加一个函数,该函数在这个过程完成后被调用。
在文档中,他们描述了以下参数:
callback=js_ident window.exports["js_ident"] will be called when prettyprinting finishes. If specified multiple times, all are called.
然而,我还没能做到这一点。很明显,我错过了回调函数应该如何定义/导出的一些内容。
我的标题看起来是这样的(当页面加载时,代码被正确地美化了,但警报没有显示(:
<script type='text/javascript'>function testing(){alert('hello')}}</script>
<script type='text/javascript' src='https://google-code-prettify.googlecode.com/svn/loader/prettify.js?callback=testing'></script>
此外,在这个例子之后,我尝试用几种不同的方式修改第一个块((下面显示的几个(,但没有改变:
<script type='text/javascript'>window['exports'] = {testing: function(){alert('123')}}</script>
<script type='text/javascript'>window.exports = {testing: {apply: function(){alert('123')}}}</script>
我应该如何定义testing
函数,以便正确调用它?
callback
参数似乎只在run_prettify.js
脚本上可用,而在您当前使用的prettify.js
脚本上不可用。
此外,根据文档,他们希望您在callback
参数中指定的函数在window.exports
对象中指定。
E.ghttp://jsbin.com/atukuq/1/
<script type='text/javascript'>
window.exports = {
testing: function () {
alert('hello');
}
}
</script>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?callback=testing"></script>
<script type='text/javascript'>
window.exports = [];
window.exports["testing"] = function() {
alert("hello");
}
</script>
<script type='text/javascript' src='https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?callback=testing'></script>
更改:用run_prettify.js代替prettify.js,并根据文档定义函数。
相关文章:
- AngularJS:我可以跳过函数参数回调吗
- 要求未定义JS回调参数
- MeteorJS:在带有回调的vzaar api上正确使用wrapAsync
- 自引用回调
- 测试Angular Service解决错误回调中的promise
- 如何将一个JavaScript函数回调为多个函数
- JavaScript回调函数
- 用于回调的javascript参数
- 将json回调数据转换为日期
- 承诺在非节点式回调上使用Bluebird
- 如何在回调函数中执行流
- 回调函数中传递参数的困难(Google Map API Markers)
- Soundcloud Javascript SDK 3.0-回调无法读取属性'connectCallback
- 如何使用jqueryAJAX从页面中回调多个变量
- jquery Onclick函数带有导致双击的回调排序函数
- Javascript点击事件回调不起作用
- 一旦加载并渲染了角度引导typeahead,就使用回调
- 成功回调永远不会被JSONP请求调用
- 如何让程序员在javascript中实现正确的回调
- 使用谷歌代码Pretify回调