|
|
|
javascript จะสร้างตัวแปรโดย loop ได้มั้ยครับ... |
|
|
|
|
|
|
|
ไม่ใช้เป็นตัวแปรแบบ object หรือ array แทนล่ะครับ แล้ววนลูปเอา
|
|
|
|
|
Date :
2013-03-06 01:26:37 |
By :
salapao_codeman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (jQuery)
<!DOCTYPE html>
<html>
<head>
<style>
div { color:blue; }
div#five { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
<div id="five"></div>
<script>
var arr = [ "one", "two", "three", "four", "five" ];
var obj = { one:1, two:2, three:3, four:4, five:5 };
jQuery.each(arr, function() {
$("#" + this).text("Mine is " + this + ".");
return (this != "three"); // will stop running after "three"
});
jQuery.each(obj, function(i, val) {
$("#" + i).append(document.createTextNode(" - " + val));
});
</script>
</body>
</html>
|
|
|
|
|
Date :
2013-03-06 09:48:52 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|