好吧,我有以下代码,按钮,当我按下它我创建divs,我想在dblclick时 在divs输入类型颜色显示和改变div的颜色dinamically但没有按钮。问题是我尝试改变的选择器,提交但它现在正在工作。这是代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style>
#toolbar{
width:600px;height: 100px;border: 3px solid;
position: absolute;left: 350px;
}
#buttons{
position: relative;top:15px;left:150px;
}
#ButtonElement{
width: 600px;border: 3px solid;position: absolute;top:200px;
height: 600px;
}
#TextElement{
width: 600px;border: 3px solid;position: absolute;top:200px;left:700px;
height: 600px;
}
</style>
</head>
<body>
<div id="toolbar">
<div id="buttons">
<button id="Button">Create Element Button</button>
<button id="Text">Create Element Text</button></div>
</div>
<div id="ButtonElement"><h2>Elements Button</h2></div>
<div id="TextElement"><h2>Elements Text</h2></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
// function Toolbar(){
// this.render=function(){
// $('body').append("<div id='toolbar'></div>");
// };
// this.init=function(){
// $("#toolbar").append("<div id='buttons'></div>");
// };
// this.createButton=function(){
// };
// }
var Colors=[];
var count=0;
function Button(count){
this.background=null;
this.count=count;
this.render=function(){
$("#ButtonElement").append("<div id=div" + this.count +">Nqkakav Tekst</div>");
};
}
Button.prototype.setBackground=function(background){
this.background=background;
};
Button.prototype.getBackground=function(){
return this.background;
};
$("#Button").click(function(){
count++;
var b=new Button(count);
b.render();
$("#div"+ count).dblclick(function(){
var diva=this;
$(this).append("<span id='colorchange'><input type='color' id='color' name='favcolor'></span>");
$("#color").change(function(){
var value=$("#color").val();
cssChange(diva,value);
});enter code here
});
});
</script>
</body>
</html>
so I just want when click on some of the divs colorpicker to show and when i click on some color to change the background of the div.
答案 0 :(得分:2)
你可以使用active:当使用.click
激活div时