forked from dciccale/Custom-radio-checkbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo4.html
155 lines (143 loc) · 5.33 KB
/
demo4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!doctype html>
<html>
<head>
<title>Demo 4 - Custom Radio-Checkbox Plugin</title>
<link href="css/demo.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/custom-radio-checkbox.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<h1>Custom Radio-Checkbox Plugin</h1>
<p id="menu">
<a href="demo1.html" title="input inside label">Demo 1</a>
<a href="demo2.html" title="input inside label without 'for' attribute">Demo 2</a>
<a href="demo3.html" title="label next to input">Demo 3</a>
<a class="current-demo" href="demo4.html" title="ajax loaded content">Demo 4</a>
</p>
<h2>Content loaded via AJAX</h2>
<p>*important: Use the <code>"for"</code> attribute in the <code><label></code> to support IE6</p>
<p>Use $('selector').customRadioCheckbox(); to replace radios & checkboxes after the content is loaded</p>
<ul id="tabs" class="clearfix">
<li><a href="#view" class="current">VIEW</a></li>
<li><a href="#html">HTML</a></li>
</ul>
<div id="content">
<div id="view" class="section">
<p><a href="ajax-loaded-content.html" id="load_content">Load content</a></p>
<div id="demo_ajax"></div>
<p><strong>Form result:</strong> <span id="result"></span></p>
</div>
<div id="html" class="section">
<p>The HTML from ajax-loaded-content.html</p>
<pre>
<code>
<form method="post" action="" id="form">
<div class="fl w200 mr10">
<h2>Radio group 1</h2>
<p>
<label for="yes">
<input type="radio" name="radioGroup1" id="yes" value="Yes" />Yes
</label>
</p>
<p>
<label for="no">
<input type="radio" name="radioGroup1" id="no" value="No" />No
</label>
</p>
<p>
<label for="maybe">
<input type="radio" name="radioGroup1" id="maybe" value="Maybe" />Maybe
</label>
</p>
</div>
<div class="fl w200">
<h2>Radio group 2</h2>
<p>
<label for="uno">
<input type="radio" name="radioGroup2" id="uno" value="Uno" />Uno
</label>
</p>
<p>
<label for="dos">
<input type="radio" name="radioGroup2" id="dos" value="Dos" />Dos
</label>
</p>
<p>
<label for="tres">
<input type="radio" name="radioGroup2" id="tres" value="Tres" />Tres
</label>
</p>
</div>
<div class="separator"></div>
<!-- checkbox -->
<p>
<label for="checkbox1">
<input type="checkbox" name="Checkbox" id="checkbox1" value="1" />Checkbox 1
</label>
</p>
<p>
<label for="checkbox2">
<input type="checkbox" name="Checkbox" id="checkbox2" value="2" />Checkbox 2
</label>
</p>
<p>
<label for="checkbox3">
<input type="checkbox" name="Checkbox" id="checkbox3" value="3" />Checkbox 3
</label>
</p>
<div class="separator"></div>
<p id="submit"><input type="submit" value="Show result" /></p>
</form>
</code>
</pre>
<p>And the jQuery to load the content:</p>
<p>After loading the content, form.customRadioCheckbox() is called to replace radios & checkboxes</p>
<pre>
<code>
$(function() {
var link = $('#load_content'),
url = link.attr('href'),
container = $('#demo_ajax');
link.click(function(e) {
e.preventDefault();
container.load(url, function() {
var form = $('#form');
// customize radio and checkbox for the loaded content
// and handle the submit function to show the results
form.customRadioCheckbox()
.submit(function(e) {
e.preventDefault();
$('#result').html(form.serialize());
});
});
});
});
</code>
</pre>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">window.jQuery || document.write('<script src="js/jquery.min.js" type="text/javascript">\x3C/script>')</script>
<script src="js/jquery.custom-radio-checkbox.js" type="text/javascript"></script>
<script src="js/demo.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
var link = $('#load_content'),
url = link.attr('href'),
container = $('#demo_ajax');
link.click(function(e) {
e.preventDefault();
container.load(url, function() {
var form = $('#form');
// customize radio and checkbox for the loaded content
// and handle the submit function to show the results
form.customRadioCheckbox()
.submit(function(e) {
e.preventDefault();
$('#result').html(form.serialize());
});
});
});
});
</script>
</body>
</html>