https://docs.google.com/file/d/0BzVXz9FRg0DWV3R0WUR2cTd5U00/edit
我需要从用户脚本中上面链接的 javascript 调用该函数。我需要该函数的代码如下所示:
jQuery(document).ready(function($) {
$('.color1').colorPicker();
});
我尝试过:
var decolorpicker = '<script type="text/javascript" scr=”www.drive.google.com/file/d/0BzVXz9FRg0DWV3R0WUR2cTd5U00/edit?usp=sharing”></script>'
$("script[src*='merged/game']").after(decolorpicker);
然后:
window.colorPicker();
这给出了错误:
Uncaught exception: TypeError: 'window.colorPicker' is not a function
我怎样才能正确地做到这一点?
最佳答案
<!-- declare your markup first -->
<div class="color1"></div>
<!-- then include your functions ( jquery also ) -->
<script src="www.drive.google.com/file/d/0BzVXz9FRg0DWV3R0WUR2cTd5U00/edit?usp=sharing"></script>
<!-- then you can apply -->
<script>
$('.color1').colorPicker();
</script>
更新:
确保链接的 JS 是 javascript 文件。 当我访问 www.drive.google.com/file/d/0BzVXz9FRg0DWV3R0WUR2cTd5U00/edit?usp=sharing 时,它会将我带到 google 文档文件。这不是 JavaScript 文件。
关于使用外部函数的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21646299/