带有jquery克隆的eyecon颜色选择器
我正在尝试复制两个输入,并将Eyecon颜色选择器添加到复制的输入中。 复制后,当我尝试单击输入添加选择颜色时,颜色将指定给上一个输入,而不是当前输入。 多谢各位带有jquery克隆的eyecon颜色选择器,jquery,colors,Jquery,Colors,我正在尝试复制两个输入,并将Eyecon颜色选择器添加到复制的输入中。 复制后,当我尝试单击输入添加选择颜色时,颜色将指定给上一个输入,而不是当前输入。 多谢各位 <link rel="stylesheet" href="ui.css" type="text/css" media="screen" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jq
<link rel="stylesheet" href="ui.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<link rel="stylesheet" media="screen" type="text/css" href="css/colorpicker.css" />
<script type="text/javascript" src="colorpicker.js"></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery('.color').ColorPicker({
onSubmit: function(hsb, hex, rgb, el) {
jQuery(el).val(hex);
jQuery(el).css('backgroundColor', '#' + hex);
jQuery(el).ColorPickerHide();
},
onBeforeShow: function () {
jQuery(this).ColorPickerSetColor(this.value);
}
});
jQuery(".cloneTableRows").live('click', function(){
var thisTableId = 'fontmanager';
var lastRow = jQuery('#'+thisTableId + " tr:first");
var newRow = lastRow.clone(true);
jQuery('#'+thisTableId).append(newRow);
jQuery('#'+thisTableId + " tr:last td:last span").css("visibility", "visible");
jQuery(newRow).find("input").each(function(){
if(jQuery(this).hasClass("color")){
jQuery(this).ColorPicker({
onSubmit: function(hsb, hex, rgb, el) {
jQuery(el).val(hex);
jQuery(el).css('backgroundColor', '#' + hex);
jQuery(el).ColorPickerHide();
},
onBeforeShow: function () {
jQuery(this).ColorPickerSetColor(this.value);
}
});
}
});
return false;
});
jQuery(".delRow").click(function(){
jQuery(this).parents("tr").remove();
return false;
});
});
</script>
<style type="text/css">
body{ font-family:Arial, Helvetica, sans-serif; font-size:13px; }
.remove {color:#cc0000}
.input{ border: solid 1px #006699; padding:3px}
.x{width:50px;margin-right:10px;}
.y{width:50px;margin-right:10px;}
</style>
</head>
<body>
<table id="fontmanager">
<tr class="clone">
<td class="font_color"><input type="text" name="color1[]" class='color'/></td>
<td class="font_shadow"><input type="text" name="color2[]" class='color'/>
</td>
<td style="background-color:transparent !important; border-bottom:0px;border-right:0px !important;"><span class="delRow" style="visibility: hidden;">X</span></td>
</tr>
</tbody>
</table>
<p><a href="#" class="cloneTableRows">Add More</a></p>
jQuery.noConflict();
jQuery(文档).ready(函数(){
jQuery('.color').ColorPicker({
onSubmit:函数(hsb、十六进制、rgb、el){
jQuery(el).val(十六进制);
jQuery(el).css('backgroundColor','#'+hex);
jQuery(el).ColorPickerHide();
},
onBeforeShow:函数(){
jQuery(this.ColorPickerSetColor)(this.value);
}
});
jQuery(“.cloneTableRows”).live('click',function(){
var thisTableId='fontmanager';
var lastRow=jQuery(“#”+thisTableId+“tr:first”);
var newRow=lastRow.clone(true);
jQuery('#'+thisTableId).append(newRow);
jQuery(“#”+thisTableId+“tr:last td:last span”).css(“可见性”、“可见”);
jQuery(newRow).find(“输入”).each(函数(){
if(jQuery(this).hasClass(“color”)){
jQuery(this).ColorPicker({
onSubmit:函数(hsb、十六进制、rgb、el){
jQuery(el).val(十六进制);
jQuery(el).css('backgroundColor','#'+hex);
jQuery(el).ColorPickerHide();
},
onBeforeShow:函数(){
jQuery(this.ColorPickerSetColor)(this.value);
}
});
}
});
返回false;
});
jQuery(“.delRow”)。单击(函数(){
jQuery(this.parents(“tr”).remove();
返回false;
});
});
正文{字体系列:Arial,Helvetica,无衬线;字体大小:13px;}
.删除{color:#cc0000}
.input{边框:实心1px#006699;填充:3px}
.x{宽度:50px;右边距:10px;}
.y{宽度:50px;右边距:10px;}
X
这里有一个工作示例:很可能您使用了不正确的方式来分配它的事件 因此您实际上是在分配事件,例如,
单击
,然后克隆它。但是,事件仅为原始输入注册。因此,克隆不知道如何处理它,因为它尚未被分配
分配事件时,可以使用live()
方法,以便它检查将来的引用
您可能还需要在live()
之前使用die()
来取消预览说明
如果上述内容不合理,请发布您的代码示例,以便我们可以尝试重新编写。一个有效的示例?哪里您的链接将我带到一个页面,要求我下载
.zip
文件。请在问题中张贴代码。我已在第一篇文章中添加了代码。克隆行时使用的是live()。