我可以修改我的按钮onclick脚本
can i modify my button onclick script
我有一个javascript代码,所以当用户按下按钮的克隆一个div被创建。代码工作得很好,但是它没有复制div的属性,所以如果原来的div有css属性的div克隆不会有属性。那么有没有一种方法可以完全复制div,甚至是它的特性呢?
$(function() {
$('.button').on('click', function(){
$('.note:first').clone().draggable().appendTo('body');
});
});
.note {
width: 280px;
height: 100px;
padding-top: 40px;
margin-top: 60px;
margin-left: 35px;
word-break: break-word;
font-family: Note;
font-size: 30px;
background-image: url("images/stickynote.png");
background-repeat: no-repeat;
background-size: cover;
z-index: 1;
}
.note img{
position:relative;
position: absolute;
top: 0px;
right: 0px;
}
.button {
position: fixed;
top: 160px;
margin-left: 44%;
border: 1px solid #000000;
background: #f2ad24;
background: -webkit-gradient(linear, left top, left bottom, from(#ffff92), to(#f2ad24));
background: -webkit-linear-gradient(top, #ffff92, #f2ad24);
background: -moz-linear-gradient(top, #ffff92, #f2ad24);
background: -ms-linear-gradient(top, #ffff92, #f2ad24);
background: -o-linear-gradient(top, #ffff92, #f2ad24);
background-image: -ms-linear-gradient(top, #ffff92 0%, #f2ad24 100%);
padding: 13px 26px;
-webkit-border-radius: 16px;
-moz-border-radius: 16px;
border-radius: 16px;
-webkit-box-shadow: rgba(255,255,255,0.4) 0 0px 0, inset rgba(255,255,255,0.4) 0 0px 0;
-moz-box-shadow: rgba(255,255,255,0.4) 0 0px 0, inset rgba(255,255,255,0.4) 0 0px 0;
box-shadow: rgba(255,255,255,0.4) 0 0px 0, inset rgba(255,255,255,0.4) 0 0px 0;
text-shadow: #7ea4bd 0 1px 0;
color: #000000;
font-size: 35px;
font-family: Note;
text-decoration: none;
vertical-align: middle;
}
.button:hover {
border: 1px solid #0a3c59;
text-shadow: #1e4158 0 1px 0;
background: #f08d24;
background: -webkit-gradient(linear, left top, left bottom, from(#ffe194), to(#f08d24));
background: -webkit-linear-gradient(top, #ffe194, #f08d24);
background: -moz-linear-gradient(top, #ffe194, #f08d24);
background: -ms-linear-gradient(top, #ffe194, #f08d24);
background: -o-linear-gradient(top, #ffe194, #f08d24);
background-image: -ms-linear-gradient(top, #ffe194 0%, #f08d24 100%);
color: #212121;
}
.button:active {
text-shadow: #1e4158 0 1px 0;
border: 1px solid #0a3c59;
background: #f09424;
background: -webkit-gradient(linear, left top, left bottom, from(#ffe194), to(#f08d24));
background: -webkit-linear-gradient(top, #ffe194, #f09424);
background: -moz-linear-gradient(top, #ffe194, #f09424);
background: -ms-linear-gradient(top, #ffe194, #f09424);
background: -o-linear-gradient(top, #ffe194, #f09424);
background-image: -ms-linear-gradient(top, #ffe194 0%, #f09424 100%);
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
HTML
<div class="note" contenteditable="true">
<span id='close' contenteditable='false' onclick='this.parentNode.parentNode.removeChild(this.parentNode)'>
<img src="images/close.png" height="25" width="25" align="right" style="vertical-align: top; float: right"/>
</span>Keep clicking this text to select
</div>
<a href='#' class='button'>Create Note</a>
您可以克隆div,将其添加到DOM中,然后使其可拖动:
var newobj = $('.note:first').clone();
// change the id, if needed
//$(newobj).attr("id","newId");
$("body").append(newobj);
$(newobj).draggable();
下面是一个jsfiddle的例子:http://jsfiddle.net/bogtan8y/
希望有所帮助
使用insertAfter jquery函数
$(function() {
$('.button').on('click', function(e){
e.preventDefault();
var test = $('div.note:first').clone();
$(test).insertAfter("div.note:last");
});
});
相关文章:
- 使用java脚本更改onClick事件中菜单选项卡的颜色
- 为什么我的javascript脚本在页面加载时运行,而不是使用onclick
- onclick'放在JavaScript脚本中时无法工作
- 使用脚本设置onclick事件
- 使用jQuery执行PHP脚本onclick
- ajax脚本使用onClick提交表单时出现问题
- 同一按钮上的连续onclick事件触发单独的脚本
- OnClick事件中的PHP脚本
- 脚本不会使用 ajax 函数 onClick 和 $_POST 获取变量
- 使用没有URL的python脚本从网页下载文件,调用onClick函数
- 如何使用 onclick 按 id 调用脚本
- 重置 onclick,以便 ajax 脚本不使用值
- CasperJS 脚本找不到正确的按钮和 onclick-event
- 如何在脚本中实现 OnClick
- 如何在脚本中实现 onclick 函数
- 为什么我的onclick脚本没有改变我的innerhtml
- 我可以修改我的按钮onclick脚本
- HTML不执行OnClick脚本
- 获取按钮onclick脚本函数自动生成的文本名称
- dom事件-JavaScript onclick脚本,用于启动带有主题和正文文本的本地邮件客户端