html - Check Id element javascript -
var jewels = new array() var index var rand var scard = [a1, a2, a3, b1, b2, b3, c1, c2, c3] function generateboard() { (var = 0; <= 8; i++) { jewels[i] = new array(); var index = math.floor(math.random() * scard.length) jewels[i] = scard[index] console.log("i:" + + jewels[i]) var yy = scard.indexof(scard[index]); scard.splice(yy, 1); } } function drawboard() { generateboard() var html = '<div class=game_background>' (var = 0; < 9; i++) { rand = math.floor(math.random() * jewels.length) html += '<div class="' + jewels[rand] + '" id="ship' + + '" style="top:' + ((i * 12) + 135) + 'px; left:245px;" ></div>' jewels.splice(rand, 1); } var newarray = [a1, a2, a3, b1, b2, b3, c1, c2, c3] }
here a1,a2,a3,b1,b2,b3,c1,c2,c3 css class.i use newarray because splice array items.now suppose element of ship2 id b3 , b3 positioned in newarray[5]. how check this(the id element positioned in number of index in array)?
<script type="text/javascript"> var jewels = new array() var index var rand var scard = ["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]; var newarray = ["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]; drawboard(); function drawboard() { var html = '<div class=game_background>' (var = 0; < 9; i++) { rand = math.floor(math.random() * scard.length); html += '<div class="' + scard[rand] + '" id="ship' + + '" style="top:' + ((i * 12) + 135) + 'px; left:245px;" ></div>' alert(newarray.indexof(scard[rand])); scard.splice(rand, 1); } } </script>
Comments
Post a Comment