Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde2aac2

Browse files
committed
Update form_collections.rst
The assignment to collectionHolder must be done within jQuery ready function, or else it will be null.BTW, the variables in JavaScript do not need the $, which is confusing since in jQuery $ has a special meaning.
1 parent7116bd0 commitde2aac2

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

‎cookbook/form/form_collections.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,27 +358,27 @@ will be show next):
358358

359359
..code-block::javascript
360360
361-
// Get the ul that holds the collection of tags
362-
var collectionHolder=$('ul.tags');
363-
364361
// setup an "add a tag" link
365-
var$addTagLink=$('<a href="#">Add a tag</a>');
366-
var$newLinkLi=$('<li></li>').append($addTagLink);
362+
var addTagLink=$('<a href="#">Add a tag</a>');
363+
var newLinkLi=$('<li></li>').append(addTagLink);
367364
368365
jQuery(document).ready(function() {
366+
// Get the ul that holds the collection of tags
367+
var collectionHolder=$('ul.tags');
368+
369369
// add the "add a tag" anchor and li to the tags ul
370-
collectionHolder.append($newLinkLi);
370+
collectionHolder.append(newLinkLi);
371371
372372
// count the current form inputs we have (e.g. 2), use that as the new
373373
// index when inserting a new item (e.g. 2)
374374
collectionHolder.data('index',collectionHolder.find(':input').length);
375375
376-
$addTagLink.on('click',function(e) {
376+
addTagLink.on('click',function(e) {
377377
// prevent the link from creating a "#" on the URL
378378
e.preventDefault();
379379
380380
// add a new tag form (see next code block)
381-
addTagForm(collectionHolder,$newLinkLi);
381+
addTagForm(collectionHolder, newLinkLi);
382382
});
383383
});
384384
@@ -393,7 +393,7 @@ one example:
393393

394394
..code-block::javascript
395395
396-
functionaddTagForm(collectionHolder,$newLinkLi) {
396+
functionaddTagForm(collectionHolder,newLinkLi) {
397397
// Get the data-prototype explained earlier
398398
var prototype=collectionHolder.data('prototype');
399399
@@ -408,8 +408,8 @@ one example:
408408
collectionHolder.data('index', index+1);
409409
410410
// Display the form in the page in an li, before the "Add a tag" link li
411-
var$newFormLi=$('<li></li>').append(newForm);
412-
$newLinkLi.before($newFormLi);
411+
var newFormLi=$('<li></li>').append(newForm);
412+
newLinkLi.before(newFormLi);
413413
}
414414
415415
..note::

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp