forked from twbs/bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (27 loc) · 948 Bytes
/
script.js
File metadata and controls
37 lines (27 loc) · 948 Bytes
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
$(document).ready(function(){
var myFormObj = {};
// We are linking the form fields to myFormObj and trigger
// the change event, so the data is updated initially.
$('#originalForm').link(myFormObj).find('input[type=text]').trigger('change');
var buttons = $('#originalForm input[type=button]');
buttons.eq(0).click(function(){
outputData('The myFormObj variable',myFormObj);
});
buttons.eq(1).click(function(){
$(myFormObj).data("name","Homer");
});
buttons.eq(2).click(function(){
outputData('This button\'s HTML5 data attribute',$(this).data('someobj'));
});
function outputData(title,obj){
try{
$('#output').html('<label>'+title+':</label><pre>'+formatObject(obj)+'</pre>');
}
catch(e){
$('#output').html('The output cannot be displayed in your browser');
}
}
function formatObject(obj){
return JSON.stringify(obj).replace(/,/g,',\n ').replace('{','{\n ').replace('}','\n}')
}
});