Подборка функций js, которая поможет уменьшить растраты на время время создания новых функций и не ставить большие Framework(и) которые будут нагружать работу браузера.
/**
* @author Sergiy Pavlenko [sergiy.pavlenko@gmail.com]
* @copyright BebeKa
* @name Commom
*/
var style = '
';
function hide(el) {
el = document.getElementById(el);
if (!el.hasAttribute('displayOld')) {
el.setAttribute("displayOld", el.style.display)
}
el.style.display = "none"
}
function show(el) {
el = document.getElementById(el);
var old = el.getAttribute("displayOld");
el.style.display = old || "";
}
function toggle(el) {
document.getElementById(el).style.display = (document.getElementById(el).style.display == 'none') ? 'block' : 'none'
}
function email(el){
var maitst = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@(([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4})$/i;
if (maitst.test(form.Temail.value) == false){
return 1;
}else{
return 0;
}
}
function getXmlHttp(){
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function post(url, send, where) {
var xmlhttp = getXmlHttp();
var params;
if(send.length == 0){ params = null; }else{ params = send; }
xmlhttp.open('POST', url, true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
document.getElementById(where).innerHTML = 'Подождите...'+style;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
document.getElementById(where).innerHTML = xmlhttp.responseText+style;
}
}
};
xmlhttp.send(params);
}
function checkAll(oForm, cbName, checked){
for (var i=0; i < oForm[cbName].length; i++) oForm[cbName][i].checked = checked;
}
* @author Sergiy Pavlenko [sergiy.pavlenko@gmail.com]
* @copyright BebeKa
* @name Commom
*/
var style = '
';
function hide(el) {
el = document.getElementById(el);
if (!el.hasAttribute('displayOld')) {
el.setAttribute("displayOld", el.style.display)
}
el.style.display = "none"
}
function show(el) {
el = document.getElementById(el);
var old = el.getAttribute("displayOld");
el.style.display = old || "";
}
function toggle(el) {
document.getElementById(el).style.display = (document.getElementById(el).style.display == 'none') ? 'block' : 'none'
}
function email(el){
var maitst = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@(([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4})$/i;
if (maitst.test(form.Temail.value) == false){
return 1;
}else{
return 0;
}
}
function getXmlHttp(){
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function post(url, send, where) {
var xmlhttp = getXmlHttp();
var params;
if(send.length == 0){ params = null; }else{ params = send; }
xmlhttp.open('POST', url, true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
document.getElementById(where).innerHTML = 'Подождите...'+style;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
document.getElementById(where).innerHTML = xmlhttp.responseText+style;
}
}
};
xmlhttp.send(params);
}
function checkAll(oForm, cbName, checked){
for (var i=0; i < oForm[cbName].length; i++) oForm[cbName][i].checked = checked;
}
Комментариев нет:
Отправить комментарий