استخدامات عملية ل$ مسج ل(). كل طريقة () لعرض

StackOverflow https://stackoverflow.com/questions/863166

  •  21-08-2019
  •  | 
  •  

سؤال

وأنا أقدم عرضا لبعض زملاء العمل اليوم على كيفية استخدام مسج مع كولد فيوجن. هذا هو أكثر من مقدمة إلى مسج من جلسة المتقدمة. أحاول إظهار كيف يمكن للمرء أن حلقة باستخدام $ (). كل طريقة مسج ل()، وفي محاولة للتوصل إلى بعض الأمثلة العملية، العالم الحقيقي، ولقد رسم فارغة. أي اقتراحات؟

هل كانت مفيدة؟

المحلول

// changes every other div green
$("div").each(function(i) { if (i % 2) this.style.backgroundColor = "green"; });

نصائح أخرى

وتخطيه. انها تريد ان تكون مربكة للمستخدمين الجدد، على أية حال. مسج يعود صفائف من الأشياء وينطبق تدعو ظيفة لكل بالفعل، والتي ليست واضحة إلى مستجد. عليك قضاء بعض الوقت على كل () و كل ما ستحصل عليه من ذلك هو أن الناس الذين لا $('a').each().css("color", "red"); أو $('a').each(function(){ $(this).css("color", "red");});

لا تسأل كيف أعرف ودي مواجهة. كل () قد ينتهي جعل هذا الخطأ.

وفحص جميع خانات في DataGrid على أساس قيمة بعض مربع خارجي

$('#<%=dgMyDataGrid.ClientID %> :checkbox').each(function(i)
{
this.checked = $(#SelectAll).is(":checked")
});

وكان في الأصل رمز وراء طريقة findcontrol () بدلا من #SelectAll، ولكن هذا يوضح أمل ما كنت أحاول القيام به. كان لا بد هذه الوظيفة أيضا إلى الحدث انقر فوق #SelectAll.

و(السماح أيضا الإشارة إلى أنني مبتدئ مسج!)

وتحرير: التنفيذ الكامل لما أنا استخدم هذا لهو href="https://stackoverflow.com/questions/709494/checkbox-in-datagrid-header-clientid-jquery"> إذا أي شخص مهتم:)

استخدام كل () في مسج

ويمكنك أن ترى محاولة مني في "أكثر / أقل" توسيع رمز بسيط جدا عمود صحيفة. هنا هو رمز والذي يستخدم وظيفة كل (). لقد عملت ليبقيه بسيط - غير عدادات، لا تخزين في فار وعدم استخدام المؤشر، وهنا هو رمز:

وانظر تجريبي الذين يعيشون وشفرة المصدر في موقعي هنا في مانيسا Turiksh

ورمز JQ


$(document).ready(function(){
$(".expand").each(function() {
$('p', this).hide(); //hide all p's for each div class=expand
$('p:first', this).show(); //show only first p in each div
$('.more',this).show(); //show more link belw each div
});

$('.more').toggle( 
    function() { 
    $(this).prevAll().show(); // toggle on to show all p's in div id=expand selected by this id=more
    $(this).html('less..'); //change legend to - less - for this id=more when div is expanded
    }, 
    function() {
    $(this).prevAll().not('p:last,h3').hide(); //hide all p's except first p, counts backwards in prevAll and reshow header h3 as it was hidden with prevAll
    $(this).html('more..'); //change legend to - more - for this id=more when div is collapsed
    });
});

كود CSS



body {font-family:calandra;font-size:10px;}
.expand {width:17%;margin-right:2%;float:left;} /*set div's as newspaper columns */
p {display:block;} /*always display p's when JS is disabled */
.more{color:red;display:none;} /*never display a's when JS is disabled */

بعض الكود


<div class="expand">
<h3>Headine 1</h3>
<p>1.A paragraph typically consists of a unifying main point, thought, or idea accompanied by supporting details. The non-fiction paragraph usually begins with the general and moves towards the more specific so as to advance an argument or point of view.</p>
<p>2. Each paragraph builds on what came before and lays the ground for what comes next. Paragraphs generally range three to seven sentences all combined in a single paragraphed statement. In prose fiction successive details, for example; but it is just as common for the point of a prose paragraph to occur in the middle or the end.</p>
<p>3 A paragraph can be as short as one word or run the length of multiple pages, and may consist of one or many sentences. When dialogue is being quoted in fiction, a new paragraph is used each time the person being quoted changed.11</p>
<p>4 The last paragraph</p>
<a href="#" class="more">more</a>
</div>


<div class="expand">
<h3>Headine 2</h3>
<p>Amet vestibulum. Nisl a, a eros ut, nec vivamus. Tortor nullam id, metus ut pretium. Amet sociis. Ut justo. Amet a est, dolor integer, purus auctor pretium.</p>
<p>Libero sapien sed, nulla nullam. Porta tincidunt. Suspendisse ante ac, eget fermentum vivamus. Ipsum sapien placerat. Adipiscing lorem magna, urna tortor dictum.</p>
<p>Fringilla a morbi, sed sollicitudin magna. Justo et in, sem aenean, molestie integer tincidunt. Magna quo, erat odio. Posuere enim phasellus, dui pede. Sit a mauris, metus suscipit.</p>
<p>Lobortis et, pellentesque nec, suspendisse elit quisque. Justo vestibulum debitis, augue fermentum. Orci et id. Ut elit, tortor ut at. Eum et non, faucibus integer nam, ac ultrices augue.</p>
<p>Ultricies magnis, velit turpis. Justo sit, urna cras primis, semper libero quam. Lectus ut aliquam. Consequat sed wisi, enim nostrud, eleifend egestas metus. Vestibulum tristique. Et erat lorem, erat sit.</p>
<p>Aliquam duis mi, morbi nisl. Rhoncus imperdiet pede. Sit et. Elit fusce, feugiat accumsan incididunt. Nec ipsum feugiat, accumsan dictum massa. Nec sit.22</p>
<a href="#" class="more">more</a>
</div>

ولقد حاولت أن يبقيه بسيط ممكن عن طريق استخدام كل ().
جون ستار

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top