Показать сообщение отдельно
  #1 (permalink)  
Старый 18.12.2018, 00:34
Интересующийся
Отправить личное сообщение для olelukoie Посмотреть профиль Найти все сообщения от olelukoie
 
Регистрация: 18.12.2018
Сообщений: 10

Добавить форму которая будет добавлять данные в массив.
Помогите пожалуйста. Нужно добавить на страницу форму, которая будет добавлять данные в массив. Скидываю всё что есть вместе с сортировкой.
<html>
<head>
<title>Сортировка таблицы средствами JavaScript</title>
<link href="css/styl.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-type" content="text/html; charset=Windows-1251">
<script language="JavaScript" type="text/javascript">
var txt = [];
var flag;
var sorted;

function weight( str ) {
var retArray = [];

for( var i = 0; i < str.length; i++ ) {
var tmp = str.charCodeAt( i );
if( tmp >= 1046 && tmp < 1078 )
tmp++;
else if( tmp == 1025 )
tmp = 1046;
else if( tmp >= 1078 )
tmp++;
else if( tmp == 1105 )
tmp = 1078;
retArray[ i ] = tmp;
}

return retArray;
}

function fillArray( years, books, authors ) {
this.years = years;
this.yweight = weight( years );
this.books = books;
this.bweight = weight( books );
this.authors = authors;
this.aweight = weight( authors );
}

function isLow( low, high, type ) {
var len1 = low[ type ].length;
var len2 = high[ type ].length;
var length = len1 < len2 ? len1 : len2;

for( var i = 0; i < length; i++ ) {
var str1 = low[ type ][ i ];
var str2 = high[ type ][ i ];
if( str1 < str2 )
return true;
if( str1 > str2 )
return false;
}

if( len1 < len2 )
return true;
return false;
}

function quickSort( l, h, type ) {
var low = l;
var high = h;
var rt = eval( "txt[ " + Math.round( ( l + h ) / 2 ) + " ]" );
var middle = new fillArray( rt.years, rt.books, rt.authors );

do {

while( isLow( eval( "txt[ " + low + " ]" ), middle, type ) )
low++;

while( isLow( middle, eval( "txt[ " + high + " ]" ), type ) )
high--;

if( low <= high ) {
var temp = txt[ low ];
txt[ low++ ] = txt[ high ]
txt[ high-- ] = temp;
}
} while( low <= high );

if( l < high )
quickSort( l, high, type );
if( low < h )
quickSort( low, h, type );
}

txt[ 0 ] = new fillArray( "Crypto ++ SDK 3.0", "Copyright © 1997-1999 Sampson Multimedia.", "1997" );
txt[ 1 ] = new fillArray( "Gus", "Gus Communications, Inc.", "2004" );
txt[ 2 ] = new fillArray( "CripKey", "Kenonic Controls Ltd.", "2010" );
txt[ 3 ] = new fillArray( "Microcosm Copy Protection", "Microcosm Copy Protection", "1996" );
txt[ 4 ] = new fillArray( "Dinkey Dongles", "Dinkey Dongles", "2003" );
txt[ 5 ] = new fillArray( "PC Guard", "Copyright © by Blagoje Ceklic", "1998" );
txt[ 6 ] = new fillArray( "SafeSerial OCX для Windows 95, 98, NT, 2000", "Sikander Soft Inc.", "1995" );
txt[ 7 ] = new fillArray( "Wibu — Key", "©1999 Copy-Protection.com.", "1999" );
txt[ 8 ] = new fillArray( "Lock & Key", "Timeless Technologies, Inc.", "2009" );
txt[ 9 ] = new fillArray( "Windows Protection Tool-Kit", "Advanced Software Technologies", "2006" );
txt[ 10 ] = new fillArray( "Hardlock Bistro", "Aladdin Knowledge Systems GmbH & Co.", "2007" );
txt[ 11 ] = new fillArray( "Sheriff", "Acudata Limited", "2002" );


function createTable( cStart, cType, cSize, cChange ) {
var tabbd = document.getElementById( "tablebody" );

if( !tabbd ) {
var table = document.getElementById( "table" );
var tbody = document.createElement( "tbody" );
tbody.id = "tablebody";
table.appendChild( tbody );
tabbd = document.getElementById( "tablebody" );
}

while( tabbd.hasChildNodes() ) {
var tmp = tabbd.childNodes[ 0 ];
tabbd.removeChild( tmp );
}


for( var counter = cStart; eval( counter + cType + cSize ); eval( "counter" + cChange ) ) {
var tr = document.createElement( "tr" );

var td = document.createElement( "td" );
var tdtxt = document.createTextNode( txt[ counter ].years );
td.appendChild( tdtxt );
tr.appendChild( td );
td = document.createElement( "td" );
tdtxt = document.createTextNode( txt[ counter ].books );
td.appendChild( tdtxt );
tr.appendChild( td );
td = document.createElement( "td" );
tdtxt = document.createTextNode( txt[ counter ].authors );
td.appendChild( tdtxt );
tr.appendChild( td );
tabbd.appendChild( tr );
}
}

function allocator( arg ) {

if( flag == arg ) {
if( sorted == "up" ) {
createTable( 0, "<", txt.length, "++" );
sorted = "down";
} else {
createTable( txt.length - 1, ">=", 0, "--" );
sorted = "up";
}
return;
}

quickSort( 0, txt.length - 1, arg );
createTable( 0, "<", txt.length, "++" );
flag = arg;
}
/script>
</head>
<body>
<div id="page-wrap">
<table border="1" id="table">
<tr>
<td><a href="javascript:allocator( 'yweight' )">Программа</a></td>
<td><a href="javascript:allocator( 'bweight' )">Разработчик</a></td>
<td><a href="javascript:allocator( 'aweight' )">Год создания</a></td>
</tr>
<tbody id="tablebody"></tbody>
</table>
<
<input type="button" onclick="UserList" value="Добавить"/>

<script language="JavaScript" type="text/javascript">
createTable( 0, "<", txt.length, "++" );
</script>
</div>
</body>
</html>
Ответить с цитированием