javascipt为元素添加按钮事件
作者:互联网
var game = null
var cnt = 0;
$(document).ready(function(e)
{
game = new obj();
});
function obj() {
cnt++;
$("#content").append('<div class = "cell" id = "square' + cnt + '"></div>');
/* var thecell = document.createElement('div');
this.parent = document.querySelector('#content');
thecell.className = 'cell';
thecell.id = 'square' + cnt;
thecell.onclick = function uuu()
{
alert(this.id);
}
this.parent.append(thecell);
*/
$('div[id="square' + cnt + '"]').click(function () {
$('div[id="square' + cnt + '"]').hide();
});
}
注释掉的为javascipt,未注释为jquery,以及它的带参数的选择器。注意点击的时候不要被别的元素挡住了
标签:function,cnt,square,javascipt,添加,按钮,var,thecell,id 来源: https://blog.csdn.net/qq_43439240/article/details/99753182