alexeyco
Новичок
Изменение положения элемента, применение xajax
Итак, Господа! Прошу помощи, невероятно устал крутить-вертеть данный код. Пример
Вопрос - почему функция move не работает так, как надо?
Итак, Господа! Прошу помощи, невероятно устал крутить-вертеть данный код. Пример
Код:
<?php
require("../xajax.inc.php"); // This is a example!!!!
$main_tpl = "<table border=\"1\" id=\"main\">\n{rows}\n</table>\n";
$row_tpl = "<tr id=\"{id}\">\n\t<td>{content}</td>\n</tr>\n";
function add_row()
{
global $main_tpl, $row_tpl;
$objResponse = new xajaxResponse();
//sleep(2); //we'll do nothing for two seconds
$search = array('{id}', '{content}');
$replace = array('new', 'This is new content box');
$row = str_replace($search, $replace, $row_tpl);
$objResponse->addAppend("main", "outerHTML", $row);
$objResponse->addScriptCall('move', 'row_4', 'new');
//$objResponse->addEvent($id, "onmouseover", "hide();");
return $objResponse;
}
$xajax = new xajax();
$xajax->debugOn();
$xajax->registerFunction('add_row');
$xajax->processRequests();
?><html>
<head>
<title>Moving Demo</title>
<?php $xajax->printJavascript("../"); ?>
<script type="text/javascript">
function move(first, second)
{
//var main = document.getElementById(main);
document.insertBefore(document.getElementById(second), document.getElementById(first));
}
</script>
</head>
<body>
<?php
$content = "";
$rows = "";
for ($i=0; $i<10; $i++) {
$search = array('{id}', '{content}');
$replace = array('row_' . $i, 'This is content for box#' . $i);
$rows .= str_replace($search, $replace, $row_tpl);
}
$content = str_replace('{rows}', $rows, $main_tpl);
echo $content;
echo "<br/><br/><a href=\"#\" onclick=\"xajax_add_row();\">Add new row after box#4</a>";
?>
</body>
</html>