时间:2021-07-01 10:21:17 帮助过:6人阅读
<div id="demo">
<div class="acts">
<label for="txtCpk"></label>边框设置:<input type="text" size="10" id="txtCpk" name="color"/>
<input type="checkbox" name="bd" value="top"/><span>上</span>
<input type="checkbox" name="bd" value="right"/><span>右</span>
<input type="checkbox" name="bd" value="bottom"/><span>下</span>
<input type="checkbox" name="bd" value="left"/><span>左</span>
</div>
<textarea id="A" cols="100" rows="29"></textarea>
</div>
</body>
<script id="js" type="text/javascript">
//<![CDATA[
//目标容器A
var $a=$("#A");
//拾色器
var $txtColor=$("#txtCpk").ColorPicker({
onChange:function(hsb,hex,rgb){
$txtColor.val("#"+hex).css("backgroundColor","#"+hex);
//联动边框-触发自定义事件"evtClick",避免改变复选框的状态
//这里可不能直接用$bd.trigger("click")噢;
//$bd.trigger("click");
$bd.trigger("evtClick");
}
});
//边框及自定义事件的应用
var $bd=$("#demo input[type='checkbox']").bind("evtClick",function(evt){
var c=this.checked?"2px solid "+$txtColor.val():"none";
$a.css("border-"+this.value,c);
}).click(function(evt){
$(this).trigger("evtClick");
});
//show the js
$(document).ready(function(){
$a.val($("#js").html());
});
//]]>
</script>
在线演示