ãjQuery in Actionããšããæ¬ã®æ¬¡ã®ç« ïŒèè
Bear BibeaultãšYehuda KatzïŒã ãŸã第äžã«ãç« ã®çºè¡ã®éã«å€§ããªã®ã£ãããããããšãèªè
ã«è¬çœªããŸãã ããããããã§ãç§ã¯ããããã£ãããã¡ãããããã¯å¬ããã ããªããç¡é¢å¿ã«ãªããªãããšãé¡ã£ãŠããŸãã ã ãããç§ãã¡ã¯ç¶ããŠããŸãã
第3ç« jQueryããŒãžã®ã¢ãã¡ãŒã·ã§ã³åã
3.1ã ãªããžã§ã¯ãã®ããããã£ãšå±æ§ã®æäœã
3.1.1ã ãªããžã§ã¯ãã®ããããã£ãæäœããŸãã
éžæããã»ããã®èŠçŽ ããã§ãã¯ãŸãã¯å€æŽããæãç°¡åãªæ¹æ³ã«ãããeachïŒïŒã³ãã³ãã䜿çšã§ããŸãã
$('img').each(function(n){
this.alt=' image['+n+'] id '+this.id;
});
ãã®åŒã¯ãæå®ãããé¢æ°ãããŒãžäžã®å<img>èŠçŽ ã«é©çšããèŠçŽ ã®ã·ãªã¢ã«çªå·ãšãã®IDã䜿çšããŠaltå±æ§ãå€æŽããŸãã
3.1.2ã3.1.3å±æ§ã®å€ã®ååŸãšå€æŽã
åŸã§èŠãããã«ãjQueryã®å€ãã®ã¡ãœããã¯ãã¡ãœããã«æž¡ãããå±æ§ãšãã®æ°ã«å¿ããŠãèªã¿åããšæžã蟌ã¿ã®äž¡æ¹ã«äœ¿çšãããŸãã
ãã®ãããattrïŒïŒã¡ãœããã䜿çšããŠãå±æ§ã®å€ã®ååŸãšèšå®ã®äž¡æ¹ãè¡ãããšãã§ããŸãã å±æ§åã®ã¿ãã¡ãœããã«æž¡ãããå Žåããã®å€ãè¿ãããŸãã次ã«äŸã瀺ããŸãã
$(â#myImageâ).attr(âaltâ)
ãã®ãããID #myImageãæã€èŠçŽ ã®altãååŸããŸãã
ãªã©ïŒ
$(â#myImageâ).attr(âaltâ,â pictureâ)
ãæ³åã®ãšãããaltãåãèŠçŽ ã®ãMy pictureãã«èšå®ããŸãã
æ°ããå±æ§å€ã®ä»£ããã«ããã®ã¡ãœããã«é¢æ°ãæž¡ãããšãã§ããããšã«æ³šæããŠãã ããã äŸïŒ
$('*').attr('title',function(index) {
return 'I am element '+index+' and my name is ' +
(this.id ? this.id : 'unset');
});
ãŸã ç§ãã¡ã«ãšã£ãŠé£ãããã®é¢æ°ã¯ãããŒãžã®ã»ããã®ãã¹ãŠã®èŠçŽ ãå®è¡ããèŠçŽ ã®ã€ã³ããã¯ã¹ãšãã®IDã«åŸã£ãŠã¿ã€ãã«å±æ§ãå€æŽããŸãã
ããã«ãattrïŒïŒã¡ãœããã䜿çšãããšãããã€ãã®å±æ§ãåæã«å€æŽã§ããŸãã
$('input').attr({value: '', title: 'Please enter a value'});
ãããã£ãŠããã¹ãŠã®å
¥åå€ãã¯ãªã¢ããã¿ã€ãã«ããå€ãå
¥åããŠãã ããããšããŠèšå®ã§ããŸãã
3.1.4å±æ§ã®åé€ã
DOMèŠçŽ ããå±æ§ãåé€ããããã«ãjQueryã«ã¯ç¹å¥ãªremoveAttrïŒïŒã¡ãœããããããŸãã äŸïŒ
$('img').removeAttr('alt');
ããã«ãããéžæãããã¹ãŠã®imgèŠçŽ ã®altå±æ§ãåé€ãããŸãã
3.2èŠçŽ ã®ã¹ã¿ã€ã«ãæäœããŸãã
3.2.1ã¯ã©ã¹åã®è¿œå ãšåé€ã
ã¯ã©ã¹å®çŸ©ã¯ãã»ããã«å«ãŸãããã¹ãŠã®èŠçŽ ã«æž¡ãããã¯ã©ã¹åãå²ãåœãŠãaddClassïŒïŒã¡ãœããã䜿çšããŠéåžžã«ç°¡åã«ãªããŸãã äŸïŒ
$('img').addClass('noBorder');
ã¯ã©ã¹ãåé€ããã«ã¯ãremoveClassïŒïŒã³ãã³ãã䜿çšããŸãã
$('img'). removeClass ('noBorder');
次ã®ã¡ãœããã¯éåžžã«èå³æ·±ããã®ã§ããtoggleClassïŒïŒã¯ããã®ã¯ã©ã¹ãå®çŸ©ãããŠããªãå Žåãã»ããå
ã®èŠçŽ ã«ã¯ã©ã¹ãå²ãåœãŠãéã«ãã¯ã©ã¹ãå²ãåœãŠãããŠããå Žåãã»ããå
ã®èŠçŽ ããã¯ã©ã¹ãåé€ããŸãã
ãã®ã¡ãœãããããŒãã«ã«é©çšãããšéåžžã«äŸ¿å©ã§ããããšãã°ãå¡ãã€ã¶ãããè¡ãçœã«ãçœã®è¡ãå¡ãã€ã¶ãã«å€æŽããå¿
èŠãããå Žåã§ãã ããã¯æ¬¡ã®ããã«è¡ãããŸãã
$('tr').toggleClass('striped');
ããã§ãstripedã¯å¡ãã€ã¶ãããè¡ã®ã¯ã©ã¹åã§ãã
3.2.2ã¹ã¿ã€ã«ã®ååŸãšèšå®ã
ã¹ã¿ã€ã«ãçŽæ¥æäœãããšã倧ããªãã£ã³ã¹ãåŸãããŸãã
cssïŒïŒã¡ãœããã¯attrïŒïŒã¡ãœãããšåæ§ã«æ©èœããèŠçŽ ã®åã
ã®CSSããããã£ãèšå®ããããåå/å€ã®ãã¢ãã¡ãœããã«æž¡ããããããã€ãã®ããããã£ãå€æŽãããããªããžã§ã¯ãã«ãããã®æ°ããå€ãæž¡ãããããããšãã§ããŸã
ããã«ããã®ã¡ãœããã¯ãããããã£ã®å€ãšããŠæž¡ãããé¢æ°ãå®å
šã«åŠçããŸãã ããšãã°ãã»ããå
ã®èŠçŽ ã®å¹
ã20ãã¯ã»ã«å¢ãããŸãã
$('div.expandable').css('width',function(){
return $(this).width() + 20 + âpxâ;
});
次ã®äŸã¯ããã©ã¡ãŒã¿ãŒã®ã°ã«ãŒãããªããžã§ã¯ããšããŠã¡ãœããã«æž¡ãå¯èœæ§ã瀺ããŠããŸãã
$('div.example').css({width: '100px', height: '200px'});
æåŸã«ãcssïŒïŒã¡ãœããã䜿çšãããšãã¡ãœããã«æž¡ãããããããã£ã®å€ãååŸã§ããŸãã ããšãã°ã次ã®ãããªèŠçŽ ã®å¹
ãèŠã€ããããšãã§ããŸãã
$('div.examle').css('width');
JQueryã«ã¯ãäžè¬çã«äœ¿çšãããããããã£çšã®ç¹å¥ãªã³ãã³ãããããŸãã ãããã£ãŠãç¹å¥ãªã¡ãœããheightïŒïŒããã³widthïŒïŒã䜿çšããŠããªããžã§ã¯ãã®é«ããšå¹
ãèŠã€ãããå€æŽãããã§ããŸãã ãããã£ãŠãã¡ãœããã«å€ãæž¡ãå Žåãåãåã£ãã¡ãœããã«åŸã£ãŠãã®å€ãèšå®ããåã«ã¡ãœãããåŒã³åºãå Žåãå¿
èŠãªå€ãååŸããŸãïŒãã®å Žåã転éãããå€ã¯ãã¯ã»ã«åäœã§èšå®ãããŸãïŒãã€ãŸãïŒ
$('div.example').width(500)
ãããã¯å¹
ã500ãã¯ã»ã«ã«èšå®ããŸãã ã¡ãªã¿ã«ãããã¯ãšåãã§ã
$('div.example').css(âwidthâ,â500pxâ)
ããã§ã次ã®ããã«ãããã¯ã®å¹
ã確èªã§ããŸãã
$('div.example').width()
3.2.3ã¹ã¿ã€ã«ãæäœããããã®ããã«äŸ¿å©ãªã³ãã³ãã
èŠçŽ ãç¹å®ã®ã¯ã©ã¹ã«å±ããŠãããã©ããã確èªããå¿
èŠãããå ŽåããããŸãã hasClassïŒïŒé¢æ°ã¯ãããè¡ãã®ã«åœ¹ç«ã¡ãŸãïŒ
$('p:first').hasClass('supriseMe')
ã»ããå
ã®èŠçŽ ãæå®ãããã¯ã©ã¹ã«å±ããå Žåãé¢æ°ã¯trueãè¿ããŸãã
3.3èŠçŽ ã®ã³ã³ãã³ãã®èšå®ã
3.3.1 HTMLãŸãã¯ããã¹ãã®çœ®ãæãã
æãåçŽãªã³ãã³ãhtmlïŒïŒã¯ããã©ã¡ãŒã¿ãŒãèšå®ãããŠããªãå Žåãæåã®å¯Ÿå¿ããèŠçŽ ã®HTMLã³ãŒããè¿ãããéžæããããã¹ãŠã®èŠçŽ ã®å
容ã§ãã©ã¡ãŒã¿ãŒãšããŠæž¡ãããHTMLãã©ã°ã¡ã³ããèšå®ããŸãã
ãŸããèŠçŽ ã®ããã¹ãã³ã³ãã³ãã®ã¿ãååŸããããšãã§ããŸãã ããã«ã¯textïŒïŒã³ãã³ãããããŸãã
<ul id="theList">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
var text=$('#theList').text();
ãã®çµæãããã¹ãå€æ°ã«ã¯æååãOneTwoThreeFourããå«ãŸããŸãã
åã®é¢æ°ãšåæ§ã«ãtestïŒïŒé¢æ°ããã©ã¡ãŒã¿ãŒãšããŠå¿
èŠãªããã¹ãã«ãªãå ŽåãèŠçŽ ã®ããã¹ãã³ã³ãã³ããèšå®ã§ããŸãã ããã«ãããã¹ãã«æå<ãŸãã¯>ãå«ãŸããŠããå Žåããããã¯ç¹æ®æåã«çœ®ãæããããŸãã
ãããã®2ã€ã®ã³ãã³ãã䜿çšããŠèŠçŽ ã®ã³ã³ãã³ããèšå®ãããšã以åã®ã³ã³ãã³ããåé€ãããããããããã®ã³ãã³ãã¯æ
éã«äœ¿çšããŠãã ããã
3.3.2ã¢ã€ãã ã®ç§»åãšã³ããŒã
æ¢åã®ã³ã³ãã³ãã®æåŸã«ã³ã³ãã³ããè¿œå ããã«ã¯ãappendïŒïŒã³ãã³ãã䜿çšããŸãã
ãã®é¢æ°ã¯ããã©ã¡ãŒã¿ãŒãšããŠæž¡ãããæååãŸãã¯HTMLãã©ã°ã¡ã³ãããæ°èŠãŸãã¯æ¢åã®DOMèŠçŽ ãŸãã¯ãã¹ããããjQueryèŠçŽ ã®ã»ããã«è¿œå ããŸãã ããã€ãã®äŸãèŠãŠã¿ãŸãããã
$('p').append('<b>some text</b>');
ãã®åŒã¯ãããŒãžäžã®ãã¹ãŠã®<p>èŠçŽ ã®æ¢åã®ã³ã³ãã³ãã®æåŸã«æž¡ãããæååããäœæãããHTMLã¹ãããããè¿œå ããŸãã
ãã®ã³ãã³ããããå
æ¬çã«äœ¿çšãããšãæ¢åã®DOMèŠçŽ ãä»ã®èŠçŽ ã®åãšããŠæå®ã§ããŸãã ããã¯ïŒ
$("p.appendToMe").append($("a.appendMe"))
appendMeã¯ã©ã¹ã®ãã¹ãŠã®åç
§ããããŒãžã¯ã©ã¹appendToMeã®ãã¹ãŠã®<p>ã®åãšããŠå²ãåœãŠãããšãã§ããŸãã ãã®å Žåãå²ãåœãŠãããèŠçŽ ã®æçµäœçœ®ã¯ãã¿ãŒã²ããèŠçŽ ã®æ°ã«äŸåããŸãã 1ã€ãããªãå Žåãå²ãåœãŠãããèŠçŽ ã¯ããŒãžäžã®å
ã®äœçœ®ãã移åãããè€æ°ã®ã¿ãŒã²ããèŠçŽ ãããå Žåãå²ãåœãŠãããèŠçŽ ã¯å
ã®å Žæã«æ®ãããã®ã³ããŒã¯ã¿ãŒã²ããèŠçŽ ã«å²ãåœãŠãããŸãã
èŠçŽ ãããå Žæããå¥ã®å Žæã«ç§»åãŸãã¯ã³ããŒããã«ã¯ãappendToïŒïŒã³ãã³ãã䜿çšããããšãã§ããŸãããã®ã³ãã³ãã¯ããã¹ããããã»ããã®ãã¹ãŠã®èŠçŽ ããé¢æ°ãã©ã¡ãŒã¿ãŒãšããŠæå®ãããã¿ãŒã²ããèŠçŽ ã®ã³ã³ãã³ãã®æåŸã«ç§»åããŸãã äŸãèŠãŠãåã®é¢æ°ãšã®éãã確èªããŸãã
$(" a.appendMe").appendTo($("p.appendToMe "))
ç¹°ãè¿ããŸãããã»ã¬ã¯ã¿ãŒãšDOMèŠçŽ ã®äž¡æ¹ãã¿ãŒã²ãããšããŠæ©èœããŸãã åã®é¢æ°ãšåæ§ã«ãã¿ãŒã²ããèŠçŽ ã1ã€ã®å Žåã移åæäœãå®è¡ãããè€æ°ã®ã¿ãŒã²ãããããå Žåãã³ããŒãå®è¡ãããŸãã
次ã®ã³ãã³ãã®åäœåçã¯ãappendïŒïŒããã³appendToïŒïŒã®åäœã«äŒŒãŠããŸãã
â¢prependïŒïŒããã³prependToïŒïŒ-ãœãŒã¹èŠçŽ ãã¿ãŒã²ããã§ã¯ãªããã¿ãŒã²ããã®åã«æ¿å
¥ããŸãã
â¢beforeïŒïŒããã³insertBeforeïŒïŒ-æåã®åã®åã§ã¯ãªããã¿ãŒã²ããèŠçŽ ã®åã«èŠçŽ ãæ¿å
¥ããŸãã
â¢afterïŒïŒããã³insertAfterïŒïŒ-æåŸã®åã®åŸã§ã¯ãªããã¿ãŒã²ããèŠçŽ ã®åŸã«èŠçŽ ãæ¿å
¥ããŸãã
次ã®äŸãèããŠã¿ãŸãããã
$('<p>!</p>').insertAfter('p img');
ãã®åŒã¯ãæ°ãã段èœãäœæãã段èœå
ã®åå³ã®åŸã«ãã®ã³ããŒãæ¿å
¥ããŸãã
3.3.3ãã¹ãèŠçŽ
ããåç
§ãããã1ã€ã®ã¿ã€ãã®DOMæäœã¯ãèŠçŽ ïŒãŸãã¯èŠçŽ ã®ã°ã«ãŒãïŒãä»ã®èŠçŽ ã«åã蟌ãããšã§ãã ããšãã°ãç¹å®ã®ã¯ã©ã¹ã®ãã¹ãŠã®ãªã³ã¯ã<div>å
ã«é
眮ããŸãã ããã¯wrapïŒïŒã³ãã³ãã䜿çšããŠå®è¡ã§ããŸãã ãã®ã¡ãœããã¯ãéžæãããèŠçŽ ã®ã»ããããéä¿¡ãããHTMLã³ãŒããŸãã¯è»¢éãããèŠçŽ ã®ã¯ããŒã³å
ã«åã蟌ã¿ãŸãã
ããšãã°ãhelloã¯ã©ã¹ã®<div>ã«ãµãã©ã€ãºã¯ã©ã¹ã®åãªã³ã¯ããã¹ãããã«ã¯ã次ã®æé ãå®è¡ããŸãã
$(âa.surpriseâ).wrap(â<div class='hello'></div>â);
ããŒãžäžã®æåã®<div>èŠçŽ ã®ã³ããŒã«åãªã³ã¯ãåã蟌ãå ŽåïŒ
$(âa.surpriseâ).wrap($(âdiv:firstâ)[0]);
éžæãããã¹ãŠã®èŠçŽ ãäžåºŠã«1ã€ã§ã¯ãªããäœããã®å
±éã®ã³ã³ããã«ãŸãšããå¿
èŠãããå Žåã¯ã©ãããã°ããã§ããããïŒ wrapAllïŒïŒé¢æ°ã¯ããã«åœ¹ç«ã¡ãŸãã
å¿
èŠãªã³ã³ããå
ã®ãã¹ãŠã®èŠçŽ ã§ã¯ãªãããã®ã³ã³ãã³ãã®ã¿ãé
眮ããå Žåã¯ãwrapInnerïŒïŒé¢æ°ã䜿çšããŸãã
3.3.4ã¢ã€ãã ã®åé€
èŠçŽ ã®ã»ãããã¯ãªãŒãã³ã°ãŸãã¯åé€ããå ŽåãremoveïŒïŒã³ãã³ãã䜿çšããŠç°¡åã«å®è¡ã§ããŸãããã®ã³ãã³ãã¯ãããŒãžäžã®DOMãããã¹ããããã»ããã®ãã¹ãŠã®èŠçŽ ãåé€ããŸãã
ä»ã®å€ãã®jQueryã³ãã³ããšåæ§ã«ããã®ã³ãã³ãã®çµæãèŠçŽ ã®ã»ããã§ããããšã«æ³šæããŠãã ããã ãŸããDOMããåé€ããŠããåãappendToïŒïŒãŸãã¯insertAfterïŒïŒãªã©ã®é¢æ°ãªã©ãä»ã®é¢æ°ã§ããã«äœ¿çšã§ããŸãã
ã³ã³ãã³ãããèŠçŽ ãã¯ãªã¢ããã«ã¯ãemptyïŒïŒã³ãã³ãã䜿çšã§ããŸãã ã»ããå
ã®ãã¹ãŠã®DOMèŠçŽ ã®å
容ãåé€ããŸãã
眮ææäœã«ã¯removeïŒïŒããã³afterïŒïŒã䜿çšããã®ãäžè¬çã§ãã ããã¯åæ§ã®æ¹æ³ã§è¡ãããŸãïŒ
$('div.elementToReplace').after('<p> </p>').remove();
ïŒïŒã¯å
ã®<div>èŠçŽ ãè¿ããããåçŽã«åé€ããŠãæ°ãã段èœ<p>ã®ã¿ãæ®ãããšãã§ããŸãã
ã¢ã€ãã¢ãæ°ã«å
¥ã£ããããããæ¹è¯ããŠæ¬¡ã®é¢æ°ãæžãããšãã§ããŸãïŒ
$.fn.replaceWith = function(html) {
return this.after(html).remove();
}
次ã«ã次ã®ããã«åã®æäœãå®è¡ããŸãã
$('div.elementToReplace').replaceWith('<p> </p>');
ããããèŠçŽ ã移åãããã³ããŒã®ã¿ãããå Žåã¯ã©ãããã°ããã§ããïŒ..
3.3.5ã¯ããŒãã³ã°èŠçŽ
ãããè¡ãããã«ãjQueryã«ã¯cloneïŒïŒã³ãã³ãããããŸãã 圌女ã¯ã»ããã®ã³ããŒãäœæããŠè¿ããŸãã ãã¹ãŠã®èŠçŽ ãšåå«ãã³ããŒãããŸãã æž¡ããããã©ã¡ãŒã¿ãŒãtrueã®å Žåããã¹ãŠã®ãã³ãã©ãŒãã³ããŒãããŸãã
ã³ããŒã§äœãããããŸã§ãèŠçŽ ã®ã¯ããŒã³ã¯éå¹ççã§ãã ããã¯ãã¹ãŠç§ãã¡ã®æ³ååã«ããã£ãŠããŸãã 次ã«äŸã瀺ããŸãã
$('img').clone().appendTo('fieldset .photo');
ãã®åŒã¯ããã¹ãŠã®ç»åã®ã³ããŒãäœæããããããåçã¯ã©ã¹ã®ãã¹ãŠã®<fieldset>èŠçŽ ã«é
眮ããŸãã
å¥ã®äŸïŒ
$('ul').clone().insertBefore('#here');
åæ§ã®æäœãå®è¡ããŸãã ããã§ã¯ãåå«<li>ïŒãã¡ãããååšããå ŽåïŒãå«ããã¹ãŠã®<ul>èŠçŽ ãè€è£œãããããšã«æ³šæããŠãã ããã
ãããŠæåŸã®äŸïŒ
$('ul').clone().insertBefore('#here').end().hide();
ãã®åŒã¯åã®æäœã«äŒŒãŠããŸãããã³ããŒãæ¿å
¥ããåŸãendïŒïŒã³ãã³ãããœãŒã¹ã»ãããéžæãããã®åŸãhideïŒïŒã³ãã³ãã§é衚瀺ã«ãªããŸãã
3.4ãã©ãŒã èŠçŽ ã®æäœ
ãã©ãŒã ã§å®è¡ãããäž»ãªã¢ã¯ã·ã§ã³ã¯ãããŒã¿ã®æäœã§ãã valïŒïŒã³ãã³ãã¯ãã»ããã®æåã®èŠçŽ ã®valueå±æ§ã®å
容ãè¿ããŸãã ãã©ãŒã èŠçŽ ã«è€æ°ã®éžæè¢ãå«ãŸããå Žåãããããã¹ãŠã®éžæè¢ããã®å€ã®é
åãè¿ãããŸãã
ãã®ã³ãã³ãã¯éåžžã«äŸ¿å©ã§ãããããã€ãã®å¶éããããŸãã ã»ããã®æåã®èŠçŽ ããã©ãŒã èŠçŽ ã§ãªãå Žåããšã©ãŒã¡ãã»ãŒãžã衚瀺ãããŸãã ãŸãããã®ã³ãã³ãã¯ãããŒã¯ããããã§ãã¯ããã¯ã¹ãšãã§ãã¯ãããŠããªããã§ãã¯ããã¯ã¹ãŸãã¯ã©ãžãªããã³èŠçŽ ãåºå¥ããŸããã
ã©ãžãªããã³ã®å Žåã次ã®ããšãã§ããŸãã
$('[name=radioGroup]:checked').val()
ãã®åŒã¯ãradioGroupãšããååã®éžæãããå¯äžã®ã©ãžãªããã³ã®å€ãè¿ããŸãïŒã©ãžãªããã³ãéžæãããŠããªãå Žåã¯undefinedãè¿ããŸãïŒã ãã®äŸã¯ãã§ãã¯ããã¯ã¹ã«é©çšã§ããŸãããããã§ã¯è€æ°ã®éžæãããå€ãå¯èœã§ããããã§ã«è¿°ã¹ãããã«ãvalïŒïŒã¯ã»ããã®æåã®èŠçŽ ã®valueå±æ§ã®å
容ãè¿ããŸãã
ã³ãã³ãã«ãã©ã¡ãŒã¿ãŒãæž¡ããšããã®ãã©ã¡ãŒã¿ãŒã¯ãã»ããã®ãã¹ãŠã®éžæãããèŠçŽ ã®å€ã®å€ãšããŠèšå®ãããŸãã ãã®å Žåããå€ãã®å¶éããããŸãã ããšãã°ãè€æ°ã®éžæé
ç®ãæã€ã¢ã€ãã ã«è€æ°ã®å€ãèšå®ããããšã¯ã§ããŸããã
valïŒïŒã䜿çšãããã1ã€ã®æ¹åã¯ããã§ãã¯ããã¯ã¹ãšã©ãžãªããã³ãã©ã°ãèšå®ãããã<select>ãªãã·ã§ã³ãéžæããããšã§ãã ãã®å Žåãå€ã®é
åãéä¿¡ããããããã®ãããããèŠçŽ ã®å€ãšäžèŽããå ŽåãèŠçŽ ãéžæïŒããŒã¯ïŒãããŸãã äŸïŒ
$('input,select').val(['one','two','three']);
ãã®åŒã¯ããã¹ãŠã®<input>ããã³<select>èŠçŽ ããã§ãã¯ããŠããããã®å€ãæž¡ãããæååïŒ1ã2ããŸãã¯3ïŒã®ãããããšäžèŽãããã©ããã確èªããŸãã å€ãäžèŽãããšããã§ãã¯ããã¯ã¹ãŸãã¯ã©ãžãªããã³ãããŒã¯ãããéžæãªãã·ã§ã³ãéžæãããŸãã
次ã®ç« ã¯çµãããŸããã åã³ãç§ã¯å¥å
šãªæ¹å€ã«åãã§ããã§ãããã ããããšãç§ã¯ããªãã«ç§ã®ããã°ã§ãã®èšäºãä»ã®èšäºããã€ã§ãèŠã€ããããšãã§ããããšãæãåºããŸããããªãã¯ããã«ãã¡ã€ã«ããããšãã§ããŸã ;-)