本文介绍了如何在Jquery中将变量的值设置为ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下代码:
var counter = 0; //counter variable
$('#divfuerimage').on('click', function(evt){
counter= counter+1; //count up
alert(counter);
var containerX = evt.pageX - $(this).offset().left,
containerY = evt.pageY - $(this).offset().top;
$('<div class="child" id=/*here the value of counter should be*/></div>')
如何使用计数器变量的值作为ID?
How can I use the Value of my Counter Variable as an ID?
推荐答案
连接字符串或创建类似这样的元素.
concatenate the string or create an element like this.
$('<div>',{
"class":"child",
"id": counter
});
这篇关于如何在Jquery中将变量的值设置为ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!