我必须动态地在javascript中使用for循环打印10个值。这里我拿标签进行打印。现在使用JavaScript动态获取标签中的选定值
当我点击标签上特定的文本,我可以告诉一个警报,该文本名称,
任何一个可以帮助我如何做到这一点。
<html>
<head>
<script type = "text/javascript">
var x = "";
function checkCookie(){
var arr = new Array("One","Two","Three");
for(var i=0; i<arr.length; i++) {
x = x + arr[i] + "<br>" + "<br>";
document.getElementById("idval").innerHTML = x;
}
}
function getItem(){
// here i want to display the selected label item
}
</script>
</head>
<body onload = "checkCookie()">
<label id = "idval" onclick = "getItem()"> </label>
</body>
</html>
显示一些代码。阅读此:http://whathaveyoutried.com – 2013-02-12 08:42:25
独自一人走,这是危险的,带着[小提琴](http://jsfiddle.net/WLKm8/)与你;) – C5H8NNaO4 2013-02-12 09:04:04
@Glutamat谢谢你,工作好 – User 2013-02-12 09:38:35