如何用js给一个DIV一个ID

	
		
			document.write("");
			titlehaed(0);
			writralldaylong();
			document.write("");
		
	
	
		
			for(j=0;j<24;j++)
			{
				document.write("");
				titles(j);
				writeTdone(j);
				document.write("");
				writeTdtwo(j);
				document.write("");
			}
		
	
functionwriteTdone(rowNum)
{
	for(i=0;i<7;i++)
	{
		document.write('');
	}
}
functionwriteTdtwo(rowNum)
{
	for(i=0;i<7;i++)
	{
		document.write('');
	}
}
functiontitles(titleNum)
{
	vartitleText=newArray("上午12点","上午1点","上午2点","上午3点","上午4点","上午5点","上午6点","上午7点","上午8点","上午9点","上午10点","上午11点","下午12点","下午1点","下午2点","下午3点","下午4点","下午5点","下午6点","下午7点","下午8点","下午9点","下午10点","下午11点");
	document.write(''+titleText[titleNum]+'');
}
functionsky(z)
{
	z=z+1;
	alert("周"+z);
}
functionwritralldaylong()
{
	for(z=0;z<7;z++)
	{
		document.write('');
	}
}
functiontitlehaed(titleNum)
{
	varheadText=newArray("GMT+08");
	document.write(''+headText[titleNum]+'');
}我是这样做的怎么给他们th里面每个加上不一样的ID呢?
我是用JS写出的一个表格7天一周那么怎么用JS在这个7个格子里面每个添加一个ID呢?
也是用JS写的请问用for写出来
HUX布斯
浏览 274回答 2
2回答

函数式编程

懒得看你代码...标题的问题回答如下...HelloWorldvardiv=document.getElementsByTagName("div")[0];div.setAttribute("id","yourdiv");alert(document.getElementById("yourdiv").innerHTML);

沧海一幻觉

这是我根据我对你的意图的猜测得出的结论functiontitles(titleNum){vartitleText=newArray("上午12点","上午1点","上午2点","上午3点","上午4点","上午5点","上午6点","上午7点","上午8点","上午9点","上午10点","上午11点","下午12点","下午1点","下午2点","下午3点","下午4点","下午5点","下午6点","下午7点","下午8点","下午9点","下午10点","下午11点");document.write(''+titleText[titleNum]+'');}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript