- 1
$("#ORDER_PROP_5 option[value='7361']").attr("selected", "selected");
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+148
$("#ORDER_PROP_5 option[value='7361']").attr("selected", "selected");
Установка значения в селекте.
+156
function postGameOrder(option) {
// 48 cтрок кода
if (option == 1) {
if (!confirm("Are you sure you want to save this configuration?")) {
return false;
}
}
// 45 строк кода
}
P.S. Умолчу уже о том, что среди тех 48 и 45 строк кода происходит обращение к глобальным переменным.
На публикацию же вдохновило то, что вот это обращение к option — единственное во всей функции.
+146
<html>
<head>
<style>
td{text-align:center;width:100;height:100;border:1px solid black}
table{border:1px solid black}
</style>
</head>
<body>
<script>
document.write("<table><tr><td>понедельник</td><td>вторник</td><td>среда</td><td>четверг</td><td>пятница</td><td>суббота</td><td>воскресенье</td></tr><tr>");
var mes=prompt('Введите месяц');
var god=prompt('Введите год');
var i;
a=new Array("январь","февраль","март","апрель","май","июнь","июль","август","сентябрь","октябрь","ноябрь","декабрь");
for(i=0;i<12;i++){if(a[i]==mes){break;}}
d=new Date(god,i,1);
n=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
if(d.getYear()%4==0){n[1]=29;}
var j=n[i];
var q=d.getDay();
if(q==0){q=7;}
for(i=2-q;i<=j;i++)
{
if(i<1){document.write("<td></td>");}
if(i>=1){ document.write("<td>"+i+"</td>"); }
if(q%7==0){document.write("</tr><tr>");}
if(i>=1){q=q+1;}
}
for(;q%7!=0;q++){document.write("<td></td>");}
document.write("</tr></table>");
</script>
</body>
</html>
Я правда спешил.
+153
$("#datepicker1").datepicker("setDate", new Date((Math.round((new Date().getTime() / 1000)) - x2) * 1000));
Из недавнего
+162
findTariffPlans = function(setValue) {findTariffPlans(setValue, null)};
findTariffPlans = function(setValue, closure) {
// bla-bla-bla
}
"Я перегрузил"
+161
function setOptionText(the_select1, the_array1, the_select2, the_array2)
{
the_select1.options.length=the_array1.length;
for (loop=0; loop < the_array1.length; loop++)
{
the_select1.options[loop].text = the_array1[loop];
the_select1.options[loop].value = the_array1[loop];
if (loop==0){
the_select1.options[loop].selected=true;
}
}
the_select2.options.length=the_array2.length;
for (loop=0; loop < the_array2.length; loop++)
{
the_select2.options[loop].text = the_array2[loop];
the_select2.options[loop].value = the_array2[loop];
if (loop==0){
the_select2.options[loop].selected=true;
}
}
}
Моему предшественнику, видимо, было лень вызывать два раза одну и ту же функцию, и потому он добавил в неё ещё два параметра и ещё девять строк кода.
+156
this.start = function() {
// Инициализирует парсинг выгрузки из Агента Плюс.
if (this.open()) {
this.catalogs = this.getTags("catalogs", true)[0].childs;
this.subdocuments = this.getTags("documents", true)[1].childs;
this.guids = this.document.childs[0].childs[0].childs;
this.sellhistory = this.getCatalog("ИсторияПродаж").childs[0].childs;
this.sellpoints = this.getCatalog("ТорговыеТочки").childs[0].childs;
this.contragents = this.getCatalog("Контрагенты").childs[1].childs;
this.deals = this.getCatalog("Договоры").childs[0].childs;
this.nomenclature = this.getCatalog("Номенклатура").childs;
this.measure = this.getCatalog("ЕдиницыИзмерения").childs[0].childs;
this.route = this.getDocument("Маршрут").childs[0].childs[0].childs[0].childs[0]
this.names = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
this.info = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
this.hash = {deals: {}, nomenclature: {}, consts: {}, contragents: {}, sellpoints: [], measure: {}};
for (var i = 0; i < this.catalogs.length; i++) {
this.names.catalog.push(this.catalogs[i].attrib.Comment.replace(/Справочник\./g, ""));
this.info.catalog.push(this.catalogs[i].attrib);
}
for (var i = 0; i < this.nomenclature[1].childs.length; i++) {
this.names.nomenclature.push(this.nomenclature[1].childs[i].attrib.Name);
this.info.nomenclature.push(this.nomenclature[1].childs[i].attrib);
this.hash.nomenclature[this.nomenclature[1].childs[i].attrib.GUID] = this.nomenclature[1].childs[i].attrib;
}
for (var i = 0; i < this.deals.length; i++) {
this.names.deals.push(this.deals[i].attrib.Name);
this.info.deals.push(this.deals[i].attrib);
this.hash.deals[this.deals[i].attrib.GUID] = this.deals[i].attrib;
}
for (var i = 0; i < this.measure.length; i++) {
this.names.measure.push(this.measure[i].attrib.Name);
this.info.measure.push(this.measure[i].attrib);
this.hash.measure[this.measure[i].attrib.GUID] = this.measure[i].attrib;
}
for (var i = 0; i < this.contragents.length; i++) {
this.names.contragents.push(this.contragents[i].attrib.Name);
this.info.contragents.push(this.contragents[i].attrib);
this.hash.contragents[this.contragents[i].attrib.GUID] = this.contragents[i].attrib;
}
for (var i = 0; i < this.sellpoints.length; i++) {
this.names.sellpoints.push(this.sellpoints[i].attrib.Name);
this.info.sellpoints.push(this.sellpoints[i].attrib);
this.hash.sellpoints[this.sellpoints[i].attrib.GUID] = this.sellpoints[i].attrib;
}
for (var i = 0; i < this.guids.length; i++) {
this.hash.consts[this.guids[i].attrib.GUID] = this.guids[i].attrib.VALUE;
}
this.dynamic.routes = new Array();
for (var i = 0; i < this.route.childs.length; i++) {
var sp = this.getSPointByGUID(this.route.childs[i].attrib.A02);
var adr = sp.Name;
var ca = this.getCAgentByGUID(this.route.childs[i].attrib.A01);
var ptypeguid = this.hash.deals[ca.A08].A06;
var cagent = ca.Name;
var dealguid = ca.A08;
var exists = false;
for (var j = 0; j < this.dynamic.routes.length; j++) if (this.dynamic.routes[j].address.trim().toLowerCase() == adr.trim().toLowerCase()) exists = exists || true;
if (!exists) this.dynamic.routes.push({ptypeguid: ptypeguid, spointguid: sp.GUID, address: adr, dealguid: dealguid, cagent: cagent, cagentguid: ca.GUID, datestamp: this.convRouteDate(this.route.childs[i].attrib.A03)});
}
} else return;
};
Маленькая часть нашего скрипта для работы с 1С - Node.JS - WebClient.
+163
jQuery("body").trigger( F11 )
Попытка перейти в полноэкранный режим.. Найдено в недрах одного довольно серьезного проекта.
+169
if(navigator.appName == "Microsoft Internet Explorer") {
for(var i=0;i<$('.product_documents').length;i++) if( ( (firstLaunch_onChangeDocs) && ($('.product_documents')[i].selectedIndex==0)) || (!firstLaunch_onChangeDocs) )
{
document.getElementById($('.product_documents')[i].id).innerHTML = '';
document.getElementById($('.product_documents')[i].id).outerHTML = document.getElementById($('.product_documents')[i].id).outerHTML.replace("</SELECT>", jsInternalDocuments + '</select>')
}
} else
for(var i=0;i<$('.product_documents').length;i++) if( ( (firstLaunch_onChangeDocs) && ($('.product_documents')[i].selectedIndex==0)) || (!firstLaunch_onChangeDocs) )
$('.product_documents')[i].innerHTML = jsInternalDocuments;
Очень альтернативная техника использования jquery.
+160
for(var i = 0, l = requestParams.length; i < l; i++) {
var param_pair = requestParams[i];
key = encodeURIComponent(param_pair[0]);
val = param_pair[1];
if ( val && val.constructor.toString().match(/array/i) ) {
val = val.join('+');
}
// ...
}
Кусочек велосипеда, который заменяет функционал jQuery.ajax
Если вдруг наш параметр оказался массивом ... ну что ж еще с ним сделать кроме как соединить через "+". Обратите внимание на саму проверку.