我必須動態地在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