Implement CheckBox control _HTC with HTC

Source: Internet
Author: User
Copy Code code as follows:

/*
Description: CheckBox control
Version: 1.1
Note: The text behind the CheckBox control follows
is to get the Htc_mylabel of the CheckBox object to display
Update add Indeter attribute to increase indeterminate selection
*/
<public:component>
<public:attach event= "Oncontentready" onevent= "Fninit ()"/>
<public:attach event= "Onpropertychange" onevent= "Fnpropertychange ()"/>
<script language= "Javascript" >
var checkboximg=window.document.createelement ("IMG");
Imagearray=[];
imagearray["Checkbox_false"]= "checkbox_false.gif";
imagearray["Checkbox_false_down"]= "checkbox_false_down.gif";
imagearray["Checkbox_false_over"]= "checkbox_false_over.gif";
imagearray["Checkbox_true"]= "checkbox_true.gif";
imagearray["Checkbox_true_down"]= "checkbox_true_down.gif";
imagearray["Checkbox_true_over"]= "checkbox_true_over.gif";
imagearray["Checkbox_indeter"]= "checkbox_indeter.gif";
imagearray["Checkbox_indeter_down"]= "checkbox_indeter_down.gif";
imagearray["Checkbox_indeter_over"]= "checkbox_indeter_over.gif";
function preload (path,obj) {
for (i in obj) {
This[i]=new Image ();
This[i].src=path+obj[i];
}
return this;
}
Preb=new preload ("images/", Imagearray);
function Fninit () {
var o=element;
if (o.type== "checkbox") {
var _table=window.document.createelement ("table");
_table.cellspacing= "0px";
_table.cellpadding= "0px";
_table.border= "0px";
if (o.disabled) {
_table.style.filter= "Alpha (opacity=50)";
}
else{
_table.style.filter= "";
}
_table.style.display= "inline";
var _tr=_table.insertrow ();
var _td=_tr.insertcell ();
if (o.checked) {
checkboximg.src=preb["Checkbox_true"].SRC;
}
else{
checkboximg.src=preb["Checkbox_false"].SRC;
}
if (o.indeter== "true") {
O.indeterminate= "true";
checkboximg.src=preb["Checkbox_indeter"].SRC;
}
_td.appendchild (CHECKBOXIMG);
_td=_tr.insertcell ();
_td.style.verticalalign= "Bottom";
if (O.htc_mylabel) {
_td.innerhtml= "<label style= ' Cursor:hand ' >" +o.htc_mylabel+ "</label>";
}
O.insertadjacentelement ("Afterend", _table);
O.style.display= "None";
_table.attachevent ("onmouseover", function () {baction ("over")});
_table.attachevent ("onmouseout", function () {baction ("Out")});
_table.attachevent ("onmousedown", function () {baction ("Down")});
_table.attachevent ("OnMouseUp", function () {baction ("Up")});
_table.attachevent ("onclick", function () {Fnclick ()});
}
}
function Fnpropertychange () {
var o=element;
Switch (event.propertyName.toString (). toLowerCase ()) {
Case "Checked":
Baction ("Up");
Break
}
}
function Fnclick () {
var o=element;
if (o.type== "checkbox") {
if (o.disabled) return;
if (o.checked) {
checkboximg.src=preb["Checkbox_false"].SRC;
}
else{
checkboximg.src=preb["Checkbox_true"].SRC;
}

o.checked=!o.checked;
}
}
function Baction (action) {
var o=element;
if (o.type== "checkbox") {
if (o.disabled) return;
if (action== "Up" | | action== "Over") {
if (o.indeterminate) {
checkboximg.src=preb["Checkbox_indeter_over"].SRC;
}
else if (o.checked) {
checkboximg.src=preb["Checkbox_true_over"].SRC;
}
else{
checkboximg.src=preb["Checkbox_false_over"].SRC;
}
}
if (action== "out") {
if (o.indeterminate) {
checkboximg.src=preb["Checkbox_indeter"].SRC;
}
else if (o.checked) {
checkboximg.src=preb["Checkbox_true"].SRC;
}
else{
checkboximg.src=preb["Checkbox_false"].SRC;
}

}
if (action== "down") {
if (o.indeterminate) {
checkboximg.src=preb["Checkbox_indeter_down"].SRC;
}
else if (o.checked) {
checkboximg.src=preb["Checkbox_true_down"].SRC;
}
else{
checkboximg.src=preb["Checkbox_false_down"].SRC;
}
O.indeterminate=false;
}
}
}
</script>
</public:component>

Test Example:
Copy Code code as follows:

<title> New Documents </title>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "Flashsoft" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "Flashsoft" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<style type= "Text/css" >

input.checkbox{
Behavior:url ("BEHAVIORS/CHECKBOX.HTC"); Cursor:hand;
}

</style>
<body>
<input name= "Chk1" type= "checkbox" class= "checkbox" htc_mylabel= "Music" checked>
<input name= "Chk1" type= "checkbox" class= "checkbox" htc_mylabel= "Sports" disabled>
<input name= "Chk1" type= "checkbox" class= "checkbox" htc_mylabel= "News" >
<input name= "Chk1" type= "checkbox" class= "checkbox" htc_mylabel= "Indeterminate property 1" indeter= "true" checked>
<input name= "Chk1" type= "checkbox" class= "checkbox" htc_mylabel= "Indeterminate property 2" indeter= "true" disabled>
<input name= "Chk1" type= "checkbox" class= "checkbox" htc_mylabel= "Indeterminate property 3" indeter= "true" >
</body>

Download this file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.