如何用类创建div [英] How to create div with class
本文介绍了如何用类创建div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个div并给他一个类,但是它不起作用. 有人可以帮我吗?
I'm trying to create a div and give him a class but it doesn't work. Could anybody help me?
$(document).ready(function() {
$('input[type=checkbox]').each(function() {
$(this).after($('<div />', {
className: 'test',
text: "a div",
click: function(e){
e.preventDefault();
alert("test")
}}));
});
});
css:
.test {
width:200px;
height:200px;
background-color:#eeeeee;
}
目前,他创建了div,但颜色不是#eeeeee
at the moment he creates the div but the color isn't #eeeeee
推荐答案
使用"class"代替className
use "class" instead of className
$('<div />', {
"class": 'test',
text: "a div",
click: function(e){
e.preventDefault();
alert("test")
}})
这篇关于如何用类创建div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文