Javascript使用外部函数

时间:2014-02-08 13:02:44

标签: javascript

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

我该如何正确地做到这一点?

1 个答案:

答案 0 :(得分:1)

<!-- 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 docs文件。这不是一个javascript文件。