Задача присвоить нужному option атрибут selected.
var sel=document.getElementById('selectid'); sel.options[10].setAttribute("selected","selected");
Специально для firefox добавляем строчку:
sel.options[10].selected=true;
Задача присвоить нужному option атрибут selected.
var sel=document.getElementById('selectid'); sel.options[10].setAttribute("selected","selected");
Специально для firefox добавляем строчку:
sel.options[10].selected=true;
Функция возвращает размеры рабочей области окна и размеры загруженной страницы сайта:
function getPageSize(){ var xScroll, yScroll, pageWidth, pageHeight, windowWidth, windowHeight; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode xScroll = document.documentElement.scrollWidth; yScroll = document.documentElement.scrollHeight; } else { // Explorer Mac...would also work in Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } if (self.innerHeight) { // all except Explorer windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } // for small pages with total width less then width of the viewport if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } return [pageWidth,pageHeight,windowWidth,windowHeight]; }
Источник: http://www.jstoolbox.com/skripty/raznoe/poluchenie-razmera-stranicy/
Использование — в примере alert, когда высота страницы больше высоты рабочей области окна, т.е. есть вертикальная полоса прокрутки:
перед закрытием body
<script type="text/javascript"> var ps=getPageSize(); if (ps[1]>ps[3]) { alert(">"); } </script>
order_from и order_to — массивы, содержащие значения дней, месяцов и лет периодов.
На выходе:
order_days — интервал в днях;budn — количество будней;vyh — количество выходных.var time_from=new Date(order_from['y'],order_from['m']-1,order_from['d']); var time_to=new Date(order_to['y'],order_to['m']-1,order_to['d']); var order_days=Math.floor((time_to.getTime()-time_from.getTime())/(1000*60*60*24)); var getday=new Date(); var vyh=0; var curday; for (i=0;i<=order_days;i++) { //getday.setDate(time_from.getDate()+i); getday.setTime(time_from.getTime()+((1000*3600*24)*i)); curday=getday.getDay(); if ((curday==0)||(curday==6)) { vyh++; } } var budn=order_days; budn=budn-vyh;
Имеется 3 select: день, месяц и год.
Задача: перезагружать select с днями в зависимости от выбранного месяца, и года — для того чтобы узнать количество дней в феврале (високосный год или нет).
В примере часть javascript, отвечающая непосредственно за перезагрузку, как рисовать сами селекты и т.д. должно быть понятно.
var order_from=new Array; var order_from_y=document.getElementById('calc_from_y'); order_from['y']=order_from_y.options[order_from_y.selectedIndex].value; var order_from_m=document.getElementById('calc_from_m'); order_from['m']=order_from_m.options[order_from_m.selectedIndex].value; var order_from_d=document.getElementById('calc_from_d'); order_from['d']=order_from_d.options[order_from_d.selectedIndex].value; var days_in_month=new Array(31,28,31,30,31,30,31,31,30,31,30,31); if ((order_from['y']%4==0)&&(order_from['m']==2)){ days_in_month[1]++; } if (order_from_d.length>days_in_month[order_from['m']-1]) { order_from_d.length=days_in_month[order_from['m']-1]; } else { for(i=order_from_d.length+1;i<=days_in_month[order_from['m']-1];i++) { order_from_d.options[order_from_d.options.length] = new Option(i,i); } }
No comment.. Все достаточно просто.
var time_from=new Date(order_from['y'],order_from['m']-1,order_from['d']); var time_to=new Date(order_to['y'],order_to['m']-1,order_to['d']); var order_days=Math.floor((time_to.getTime()-time_from.getTime())/(1000*60*60*24));
http://belonogov.blogspot.com/2009/01/blog-post_12.html
<select id="selectid" name="selectname" onchange="location = this.options[this.selectedIndex].value;"> <option value="/page1">Страница 1</option> <option value="/page2">Страница 2</option> </select>
Javascript:
function printBlock() { $("input").each(function(){ $(this).attr("value", $(this).val()); }); $("select").each(function(){ var val=$(this).val(); $("option[value='"+val+"']", this).attr('selected', 'selected'); }); var PrintContent=$('#PrintContent').html(); $('body').addClass('printSelected'); var Logo='<div class="printLogo"><img src="/templates/images/logo.gif" alt=""/></div>'; var Contacts='<div class="printPhone"><b>Адрес</b><br/>Телефон</div><div style="clear:both;"></div>'; $('body').append('<div class="printSelection">'+Logo+Contacts+PrintContent+'</div>'); var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; if (!is_chrome) { window.print(); window.setTimeout(pageCleaner,0); } else { document.onmousemove=window.print(); window.setTimeout(pageCleaner,1000); } return false; } function pageCleaner() { $('body').removeClass('printSelected'); $('.printSelection').remove(); }
CSS:
/*-------------------- PRINTER --------------------*/ .printLogo {float:left;} .printPhone {float:right;margin-right:10px;} .printPhone td{vertical-align:top;padding-right:25px;} .printSelected { background: #ffffff; padding: 10px; } .printSelected div { display:none; } .printSelected div.printSelection { display:block; } .printSelected div.printSelection div { display:block; } .printlink { float:right; } .printlink img{ cursor:pointer; }
HTML :
<div class="printlink" onclick='printBlock();'><img alt="Распечатать" src="/images/print.gif" /></div> <div id="PrintContent"> ... </div>