Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Вебмастеру (http://forum.oszone.net/forumdisplay.php?f=22)
-   -   jQuery работает только если дублирую код (http://forum.oszone.net/showthread.php?t=192599)

darksmoke 29-11-2010 16:23 1554233

jQuery работает только если дублирую код
 
Добрый день
Зацикливается код. Т.е. Если к примеру я жму кнопку удалить, то один раз все удаляется, на второй уже не удаляется. Если я код еще раз продублирую, то будет удаляться 2 раза. Три раза продублирую, три раза будет удалятся.
Я ж понимаю что как то можно без дублирования кода сделать, а как?
PHP код:

<!DOCTYPE html PUBLIC  "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Города - Админ панель</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="../js/jquery-1.4.3.min.js" type="text/javascript"></script>
    <script src="../js/jquery.jeditable.mini.js" type="text/javascript"></script>
    <script src="../js/jquery-ui-1.8.6.custom.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
        $(document).ready(function() {
           /* Перетаскивание меню */
           $(function() {
                $("#contentLeft ul").sortable({  
                    opacity        : 0.6,  
                    cursor        : 'move',  
                    placeholder    : "ui-state-highlight",  
                    pacity        : 0.6,
                    update        : function() {
                        var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
                        $.post("action/citiesListing.php", order, function(theResponse){
                        $("#contentRight").html(theResponse);
                        });
                    }
                });
            });
 
            /* Динамическое редактирование */
            $(".editable").editable("action/citiesEdit.php",
            {
                cancel    : 'Отмена',
                submit    : 'Сохранить',
                event     : 'dblclick',
                indicator : '<img src="img/ajax-loader.gif" alt="" />',
                tooltip : "Щелкните чтоб отредактировать этот текст"
            });
            
            /* Сохраняем новый город */
            $('#citiesCreate').click(function(){
                $.post("action/citiesCreate.php",{citiesCreate: $('#addCity').val()}, function(citiesCreate){
                    $("#contentLeft").html(citiesCreate);
                    $('#addCity').attr({value: ''});
/* Дублирование кода */                    
                    $("#contentLeft ul").sortable({  
                        opacity        : 0.6,  
                        cursor        : 'move',  
                        placeholder    : "ui-state-highlight",  
                        pacity        : 0.6,
                        update        : function() {
                            var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
                            $.post("action/citiesListing.php", order, function(theResponse){
                            $("#contentRight").html(theResponse);
                            });
                        }
                    });
/* Конец дублирования кода */
                    
                });
            });
            
            /* Кнопка для красаты */
            $('#citiesCreate').hover(
                function(){
                        $(this).addClass("ui-state-hover");
                },
                function(){
                        $(this).removeClass("ui-state-hover");
                }
                ).mousedown(function(){
                    $(this).addClass("ui-state-active");
                })
                .mouseup(function(){
                    $(this).removeClass("ui-state-active");
            });
            
            /* Удаляем город */
            $('ul a').click(function(){
                $.post("action/citiesDelete.php",{citiesDelete: this.id}, function(citiesDelete){
                    $("#contentLeft").html(citiesDelete);
/* Дублирование кода */                        
                    
                    $("#contentLeft ul").sortable({  
                        opacity        : 0.6,  
                        cursor        : 'move',  
                        placeholder    : "ui-state-highlight",  
                        pacity        : 0.6,
                        update        : function() {
                            var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
                            $.post("action/citiesListing.php", order, function(theResponse){
                            $("#contentRight").html(theResponse);
                            });
                        }
                    });
                    
                    $(".editable").editable("action/citiesEdit.php",
                    {
                        cancel    : 'Отмена',
                        submit    : 'Сохранить',
                        event     : 'dblclick',
                        indicator : '<img src="img/ajax-loader.gif" alt="" />',
                        tooltip : "Щелкните чтоб отредактировать этот текст"
                    });
                    
/* Конец дублирования кода */
                });
            });
        });
        -->
    </script>
    <link rel="stylesheet" type="text/css" href="jquery-ui-1.8.6.custom.css" media="all" />
    <style type="text/css">
    input.text, input.file, textarea, select { margin-bottom:12px; width:30%; padding: 0.4em; }
    label, input, textarea, select {display: block}
    #contentLeft a{float:right; position: relative; top:-20px}
    </style>
</head>
<body>
<?php
require_once '../../inc/connectRead.php';
 
$link mysql_connect($localhost$dbUser$dbPassword) or die('Не могу подключится к БД');
mysql_select_db($dbName$link);
mysql_set_charset('utf8'$link);
 
echo 
'<div id="contentRight" class="ui-widget"></div>
 
    <form method="post">
        <fieldset><legend> Добавить город </legend>
        <input type="text" name="addCity" id="addCity" class="text ui-widget-content ui-corner-all" />
        <input type="button" value="Добавить город" id="citiesCreate" class="ui-button ui-state-default ui-corner-all" />
        </fieldset>
    </form>'
;
 
$queryCities mysql_query("SELECT * FROM `cities` ORDER BY `sort`");
 
echo 
'<div id="contentLeft"><ul>';
 
while (
$rowCities mysql_fetch_assoc($queryCities))
{    
   echo 
'<li id="recordsArray_',stripslashes($rowCities['id']),'" class="ui-widget-content ui-corner-all" style="padding:0.3em; margin:0.1em; list-style:none;"><span class="editable" id="',stripslashes($rowCities['id']),'">'stripslashes($rowCities['name']),'</span><a href="#" title="Удалить" class="ui-icon ui-widget-content  ui-icon-trash" style="float:right; position:relative; top:0px;right:10px" id="delete_',stripslashes($rowCities['id']),'"></a></li>';  
}
 
echo 
'</ul></div>';
 
 
mysql_close($link);
?>
</body>
</html>



Время: 15:38.

Время: 15:38.
© OSzone.net 2001-