Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   Цикл while + немного jquery (https://javascript.ru/forum/events/20874-cikl-while-nemnogo-jquery.html)

Андрей38 04.09.2011 21:09

$(document).ready(function () {
		var i = 0; // создаем переменную i
		while(i < 4){ // делать пока i меньше 4
(function(i){
			$("#test"+i).click(function(){viewInfo(i)}) // для каждой кнопки выставлем функцию с параметром её id
})(i++);	
	}
	
		
		})
	function viewInfo(id) //собственно ,сама функция вывода id
	{
		alert(id) 
	}

http://szenprogs.ru/blog/jquery_vstr.../2010-10-13-89

http://myrusakov.ru/cikly-javascript.html
<!-- * http://myrusakov.ru/cikly-javascript.html-->
<script type="text/javascript">
for (i = 0; i < 30; i++) {
	  if (i <20) continue;
//  if (i == 10) break;
 // document.write( ' <div  id='+i+'> id= '+i+' </div>  ' )
  alert( ' <div  id='+i+'> id= '+i+' </div>  ' );
}
</script>

http://xhtml.co.il/ru/jQuery/toArray
http://xhtml.co.il/ru/jQuery/Типы/Массив
http://xhtml.co.il/ru/jQuery/get !!!!!!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>

  $(document).ready(function(){
    $("*", document.body).click(function (e) {
      e.stopPropagation();
      var domEl = $(this).get(0);
    alert(domEl.tagName);
    });
  });
  </script>
  <style>
  span { color:red; }
  div { background:yellow; }
  </style>

</head>
<body>
  <span> </span>
  <p>In this paragraph is an <span>important</span> section</p>

  <div><input type="text" /></div>
</body>
</html>

http://szenprogs.ru/blog/jquery_vstr.../2010-10-13-89

Андрей38 19.10.2011 01:35

что быстрее _for c ленгзом или each?
<!DOCTYPE html>
<html>
<head>
  <style>
  span { color:red; }
  </style>

<script src="http://code.jquery.com/jquery-1.5.js" type="text/javascript"></script>
  
  <script type="text/javascript" language="javascript">
     $(document).ready(function(){
  var es=$('div')
      for (var i = 0; i <es.length; i++)
	   {
es.eq(i) .clone().wrap('p').appendTo ('#df')

	  
	   }  
    
  
     });
  </script>
<div id='df'> </div>
</head>
<body>
  Reversed - <span></span>
  <div>One</div>
  <div>Two</div>
  <div>Three</div>
</body>
</html>


Ну и альтернатива этому--- c обычным each в связке с this...Что будет работать быстрее?
Какой вариант предпочтительнее , уважаемые гуру?..
.. а в сравнении с регуляр.выражением?..
И каким секундомером мерять:) ?


Часовой пояс GMT +3, время: 01:13.