我在使用select2表格时遇到了麻烦,我整晚都在忙着弄清楚。我一直试图让多选框工作,我只能让前几个工作。我有一种感觉,我有javascript错误,但我现在无法思考。请帮我。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Select2 3.1 - Tabbing out doesn't put placeholder back - jsFiddle demo</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
<link rel="stylesheet" type="text/css" href="/css/normalize.css">
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<script type='text/javascript' src="http://ivaynberg.github.com/select2/select2-master/select2.js"></script>
<link rel="stylesheet" type="text/css" href="http://ivaynberg.github.com/select2/select2-master/select2.css">
<style type='text/css'>
.selectContainer {
margin: 20px;
padding: 200px;
}
</style>
<script type='text/javascript'>//<![CDATA[
$(function(){
$('#e1').select2({
data: [{id:0, text:'Haircut Woman'}, {id:1, text:'Haircut Men'}, {id:2, text:'Haircut Children'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:4, text:'Hair Coloring'}, {id:5, text:'Tinting Semi/Permanent'}, {id:6, text:'Full Weave'}, {id:7, text:'Cap Frost'}, {id:8, text:'Partial Highlights/Lowlights'}, {id:9, text:'Single Foil'}, {id:10, text:'Color Gloss'}, {id:11, text:'Color Remove'}, {id:12, text:'Color Corrective'}, {id:13, text:'Reconstruction'}, {id:14, text:'Hair Styling'}, {id:15, text:'Shampoo and Style'}, {id:16, text:'Updo'}, {id:17, text:'Wedding Updo'}, {id:18, text:'Straightening'}, {id:19, text:'Deep Conditiong'}, {id:20, text:'Hair Texture'}, {id:21, text:'Inventive Perms'}, {id:21, text:'Body Waves'}, {id:22, text:'Hair Straightening'}, {id:23, text:'Chemical Straightening'}, {id:24, text:'Japanese Straightening'}, {id:25, text:'Karatin Blowout'}, {id:26, text:'Karatin Treatment'}, {id:27, text:'Hair Extension '}, {id:1, text:'Hair Extension Weaving'}, {id:2, text:'Single Hair Extension'}, {id:28, text:'Feather Hair Extension'}, {id:29, text:'Sparkle Extension'}],
multiple: true
});
$('#e3').select2({
data: [{id:0, text:'Gel Full Set'}, {id:1, text:'Gel Fill'}, {id:2, text:'Gel Color'}, {id:3, text:'Silk Full Set'}, {id:3, text:'Silk Fill'}, {id:3, text:'Acrylic Full Set'}, {id:3, text:'Acrylic Fill'}, {id:3, text:'Solar Full Set'}, {id:3, text:'Solar Fill'}, {id:3, text:'Solar Pink & White Fill'}, {id:3, text:'Paraffin Wax'}, {id:3, text:'Nail Art'}, {id:3, text:'3D Nail Art'}, {id:3, text:'French'}, {id:3, text:'Hand Polish Change'}],
multiple: true
});
$('#e4').select2({
data: [{id:0, text:'Derm Renew Facial'}, {id:1, text:'Thermo Plastic Facial'}, {id:2, text:'Algomask +Cooling Thermo'}, {id:3, text:'Corrective Mask Facial'}, {id:3, text:'Collagen 90'}, {id:3, text:'Sea C Spa'}, {id:1, text:'Botinol “Botox like Effect”'}, {id:2, text:'Micro-Dermabrasion Treatment'}, {id:3, text:'Home Facial'}, {id:3, text:'European Facial'}, {id:3, text:'Dark Eye Circle & Puffiness'}, {id:3, text:'Acne Treatment Facial'}, {id:3, text:'Chemical Peel Treatment'}, {id:3, text:'Skin Tags, Brown Spot'}, {id:3, text:'Freckle, Mole Removal'}],
multiple: true
});
$('#e5').select2({
data: [{id:0, text:'Eyebrow'}, {id:1, text:'Lip'}, {id:2, text:'Chin'}, {id:3, text:'Freckle, Mole Removal'}, {id:3, text:'Face'}, {id:3, text:'Half Legs'}, {id:3, text:'Full Legs'}, {id:3, text:'Under Arms'}, {id:3, text:'Half Arms'}, {id:3, text:'Full Arms'}, {id:3, text:'Bikini'}, {id:3, text:'Brazilian'}, {id:3, text:'Stomach'}, {id:3, text:'Back'}, {id:3, text:'Shoulder'}, {id:3, text:'Neck'}, {id:3, text:'Neck'}],
multiple: true
});
$('#e6').select2({
data: [{id:0, text:'Body Bronzing'}, {id:1, text:'Full Legs Bronzing'}, {id:2, text:'Sparkle Extension'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:1, text:'Haircut Men'}, {id:2, text:'Haircut Children'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}, {id:3, text:'Hair Trim Bang or Neck'}],
multiple: true
});
$('#e7').select2({
data: [{id:0, text:'Bridal Make-Up'}, {id:1, text:'Make-Up Application'}, {id:2, text:'Lash or Brow Tinting'}, {id:3, text:'Eye Lash Perm'}, {id:3, text:'Flare Eye Lash Extension'}, {id:3, text:'Single Lash Extension'}, {id:3, text:'Airbrush Make-Up'}],
multiple: true
});
$('#e8').select2({
data: [{id:0, text:'30 Minutes'}, {id:1, text:'60 Minutes'}, {id:2, text:'90'}],
multiple: true
});
$('#e9').select2({
data: [{id:2, text:'15 Minutes'}{id:0, text:'30 Minutes'}, {id:1, text:'60 Minutes'}, {id:2, text:'90 Minutes'}],
multiple: true
});
$('#e10').select2({
data: [{id:0, text:'1 Session'}, {id:1, text:'3 or More Sessions'}, {id:2, text:'6 or More Session'}],
multiple: true
});
$('#e11').select2({
data: [{id:0, text:'1 Session'}, {id:1, text:'3 or More Sessions'}, {id:2, text:'6 or More Session'}],
multiple: true
});
$('#e12').select2({
data: [{id:0, text:'Eyebrow'}, {id:1, text:'Eyebrow Hair Stroke'}, {id:2, text:'Eye Liner'}, {id:3, text:'Eye Liner Upper & Lower'}, {id:4, text:'Lip Liner'}, {id:5, text:'FUll Lip'}, {id:6, text:'COrrective'}],
multiple: true
});
});//]]>
</script>
</head>
<body>
<div class="selectContainer">
<p>
<label for="e1">Hair Service</label>
<input type="text" id="e1" placeholder="Select all that apply" />
</p>
<br/>
<p>
<label for="e2">Nails Service</label>
<input type="text" id="e2" placeholder="Select all that apply" />
</p>
<br/>
<p>
<label for="e3">Specialized Nails</label>
<input type="text" id="e3" placeholder="Select all that apply" />
</p>
<BR>
<p>
<label for="e4">Skin Care</label>
<input type="text" id="e4" placeholder="Select all that apply" />
</p>
<BR>
<p>
<label for="e5">Face & Body Waxing</label>
<input type="text" id="e5" placeholder="Select all that apply" />
</p>
<BR>
<p>
<label for="e6">Body Bronzing</label>
<input type="text" id="e6" placeholder="Select all that apply" />
</p>
<p>
<label for="e7">Cosmetic</label>
<input type="text" id="e1" placeholder="Select all that apply" />
</p>
<br/>
<p>
<label for="e8">Massage</label>
<input type="text" id="e2" placeholder="Select all that apply" />
</p>
<br/>
<p>
<label for="e9">Slimming & Toning Stomach Treatment</label>
<input type="text" id="e3" placeholder="Select all that apply" />
</p>
<BR>
<p>
<label for="e10">Body Wrap</label>
<input type="text" id="e4" placeholder="Select all that apply" />
</p>
<BR>
<p>
<label for="e11">Double Chin</label>
<input type="text" id="e5" placeholder="Select all that apply" />
</p>
<BR>
<p>
<label for="e12">Permanent Make-Up Tattooing</label>
<input type="text" id="e6" placeholder="Select all that apply" />
</p>
<br/>
</div>
</body>
</html>
答案 0 :(得分:4)
原因是定义数组时出现语法错误(缺少逗号),您应该在控制台中看到它。
$('#e9').select2({
data: [{id:2, text:'15 Minutes'},{id:0, text:'30 Minutes'}, {id:1, text:'60 Minutes'}, {id:2, text:'90 Minutes'}],
^___ This comma was missing
multiple: true
});
<强> Fiddle 强>
还要确保最后5-6个选项的ID是正确的(似乎是复制粘贴问题)
答案 1 :(得分:0)
浪费了一个多小时之后,我在Select2 Docs中发现了这个:
$('#profession').select2().val([1,2]).trigger("change")
这里1,2是值,#profession是select-option的id。
SHORT-SWEET-SIMPLE!