Test Case Boilerplate
HTML
<!DOCTYPE html>
<html><body></body></html>
CSS
body{
max-width:480px;
}
#test_jquery{
width:200px;
}
#test_jquery > *{
width:100%;
display:block;
}
.test_resilt{
line-height:40px;
}
.test_resilt .parent_row{
width:100%;
clear:both;
}
.test_resilt .row{
height:40px;
font-size:25px;
padding:0 1em;
border:1px solid #fff;
float:left;
width:100px;
}
.test_resilt .row[class~=good]{background-color: #7BE04B;}
.test_resilt .row[class~=woefully]{background-color: #FF5F5F;}
JavaScript
$(document).ready(function(){
$.test();
});
$.test = function(){
var test_result = {
'text' : {},
'password' : {},
'radio' : {},
'checkbox' : {},
'checkbox2' : {},
'select' : {},
'select2' : {},
'textarea' : {}
};
//=================================================================================================
//Start form
var form = "\
<form id='test_jquery'>\
<input class='text' name='text' type='text' value='bug'>\
<input class='password' name='password' type='password' value='bug'>\
<div>\
<input class='radio' name='radio' type='radio' value='bug' checked='checked'> Bug<br>\
<input class='radio OK' name='radio' type='radio' value='OK'> OK\
</div>\
<div>\
<input class='checkbox' name='checkbox' type='checkbox' checked='checked'> Bug<br>\
<input class='checkbox2' name='checkbox2' type='checkbox'> OK\
</div>\
<select class='select' name='select'>\
<option value='bug' selected='selected'>Bug 1</option>\
<option class='OK' value='OK'>OK</option>\
<option value='3'>Bug 2</option>\
</select>\
<select class='select2' name='select2'></select>\
<textarea class='textarea' name='textarea'>bug</textarea>\
</form>\
";
var $form = $(form);
$('body').append($form);
//=================================================================================================
//Create option from JS
var option = [
['Bug 1', 'bug', true],
['OK', 'OK', false],
['Bug 2', 'bug2', false],
];
var $option = $('<option>');
for(i in option){
var $elem = $option.clone(true);
$elem.text(option[i][0]);
$elem.val(option[i][1]);
$elem.addClass(option[i][1]);
...