简体   繁体   English

jQuery colorpicker无法与Ajax一起使用

[英]jQuery colorpicker not working with Ajax

I've an input field in my backend where I use a jQuery colorpicker to make it easier for users to get the hex value of a color. 我在后端有一个输入字段,在其中使用jQuery配色器,使用户更容易获得颜色的十六进制值。 It's working good so far. 到目前为止,一切正常。

But, as the inputfields are created with ajax, I need to get to them with an 'jQuery ajax call'. 但是,由于输入字段是使用ajax创建的,因此我需要使用“ jQuery ajax调用”来访问它们。

For some reasons this gives me a javascript error 'TypeError: undefined is not an object (evaluating 'pos.top')' in the colorpicer lib js file. 由于某些原因,这使我在colorpicer lib js文件中出现了JavaScript错误“ TypeError:undefined不是对象(正在评估'pos.top')”。

Without asking you to grab thought the asset lib, is someone able to point me in the right direction as to why this error arises? 不用问您是否想起资产库,是否有人可以向我指出错误原因的正确方向? I mean the calls are pretty similar, aren't they? 我的意思是电话非常相似,不是吗? What am I missing? 我想念什么?

Here's my code. 这是我的代码。

Working version (after saving the page): 工作版本(保存页面后):

jQuery('.ci-js-colorpicker').click(function(){  }).ColorPicker();

Not working version (with jQuery ajax call): 不起作用的版本(使用jQuery ajax调用):

jQuery(document).on('click','.ci-js-colorpicker',function(){  }).ColorPicker();

I've removed parts of the code in the function to make it easier to read. 我删除了函数中的部分代码,以使其更易于阅读。 The jQuery colorpicker lib I'm using is: http://www.eyecon.ro/colorpicker/ 我正在使用的jQuery colorpicker lib是: http ://www.eyecon.ro/colorpicker/

Try doing: 尝试做:

$(document).on('click', '.ci-js-colorpicker', function () {
  $('.ci-js-colorpicker').colorpicker();
});

If you are displaying it in a modal, maybe you want to make the horror of: 如果要以模式显示它,则可能要惊恐于:

.colorpicker-visible {z-index: 9999;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM