Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ajax、php和sql_Php_Sql_Ajax - Fatal编程技术网

ajax、php和sql

ajax、php和sql,php,sql,ajax,Php,Sql,Ajax,我的页面上有一个DB表中的项目列表 选中时,我正在尝试更改图示符图标 <div class="div1"> <span id=".<?php echo $row['id']; ?>" style="color:black;" class="glyphicon glyphicon-eye-open"> </span> </div> 您只需删除并添加新类: $(document).ready(function(){ $(".

我的页面上有一个DB表中的项目列表 选中时,我正在尝试更改图示符图标

<div  class="div1">
<span  id=".<?php echo $row['id']; ?>" style="color:black;" class="glyphicon glyphicon-eye-open"> </span>
</div>


您只需删除并添加新类:

$(document).ready(function(){
    $(".div1").click(function(){
        $(this).children('span').removeClass('glyphicon-eye-open');
        $(this).children('span').addClass('glyphicon-ok');

        //Here you can add ajax call

    });
});

您只需删除并添加新类:

$(document).ready(function(){
    $(".div1").click(function(){
        $(this).children('span').removeClass('glyphicon-eye-open');
        $(this).children('span').addClass('glyphicon-ok');

        //Here you can add ajax call

    });
});

当您所做的只是删除一个类并将一个新类添加到一个span中时,无需一直到服务器获取一个新span

同样使用正确的作用域,
$(this)
将阻止它影响所有
div1
元素

<script>
$(document).ready(function(){
    $(".div1").click(function(){
        //$(".div1").load("clicked.php");
        $(this).children('span').removeClass('glyphicon-eye-open');
        $(this).children('span').addClass('glyphicon-ok');
    });
});
</script>

$(文档).ready(函数(){
$(“.div1”)。单击(函数(){
//$(“.div1”).load(“clicked.php”);
$(this).children('span').removeClass('glyphicon-eye-open');
$(this).children('span').addClass('glyphicon-ok');
});
});
并使代码在每次单击时从一个切换到另一个

<script>
    $(document).ready(function(){
        $(".div1").click(function(){
            if ( $(this).children('span').hasClass('glyphicon-ok') ) {
                $(this).children('span').removeClass('glyphicon-ok');
                $(this).children('span').addClass('glyphicon-eye-open');
            } else {
                $(this).children('span').removeClass('glyphicon-eye-open');
                $(this).children('span').addClass('glyphicon-ok');
            }
        });
    });
    </script>

$(文档).ready(函数(){
$(“.div1”)。单击(函数(){
if($(this).children('span').hasClass('glyphicon-ok')){
$(this).children('span').removeClass('glyphicon-ok');
$(this).children('span').addClass('glyphicon-eye-open');
}否则{
$(this).children('span').removeClass('glyphicon-eye-open');
$(this).children('span').addClass('glyphicon-ok');
}
});
});

当您所做的只是删除一个类并将一个新类添加到一个span中时,无需一直到服务器获取新span

同样使用正确的作用域,
$(this)
将阻止它影响所有
div1
元素

<script>
$(document).ready(function(){
    $(".div1").click(function(){
        //$(".div1").load("clicked.php");
        $(this).children('span').removeClass('glyphicon-eye-open');
        $(this).children('span').addClass('glyphicon-ok');
    });
});
</script>

$(文档).ready(函数(){
$(“.div1”)。单击(函数(){
//$(“.div1”).load(“clicked.php”);
$(this).children('span').removeClass('glyphicon-eye-open');
$(this).children('span').addClass('glyphicon-ok');
});
});
并使代码在每次单击时从一个切换到另一个

<script>
    $(document).ready(function(){
        $(".div1").click(function(){
            if ( $(this).children('span').hasClass('glyphicon-ok') ) {
                $(this).children('span').removeClass('glyphicon-ok');
                $(this).children('span').addClass('glyphicon-eye-open');
            } else {
                $(this).children('span').removeClass('glyphicon-eye-open');
                $(this).children('span').addClass('glyphicon-ok');
            }
        });
    });
    </script>

$(文档).ready(函数(){
$(“.div1”)。单击(函数(){
if($(this).children('span').hasClass('glyphicon-ok')){
$(this).children('span').removeClass('glyphicon-ok');
$(this).children('span').addClass('glyphicon-eye-open');
}否则{
$(this).children('span').removeClass('glyphicon-eye-open');
$(this).children('span').addClass('glyphicon-ok');
}
});
});

因为您的jquery选择器,所以您应该选择id元素。@他的选择器是正确的。
$(this.load(“clicked.php”):将更改的范围限制为单击的元素。替换
$(“.div1”).load(“clicked.php”)$(this.load)(“clicked.php”)
并让我们知道它是否有效。您不需要从服务器加载一段新的HTML来执行此操作,只需更改span
以移除
glyphicon眼睛睁开
,并将其替换为
glyphicon ok
,因为您的jquery选择器应该选择id元素。@lighter他的选择器是正确的。
$(this.load(“clicked.php”);
:将更改的范围限制在单击的元素上。将
$(.div1”).load(“clicked.php”);
替换为
$(this.load(“clicked.php”)
并让我们知道它是否有效。您不需要从服务器加载新的HTML来执行此操作,只需更改span
以移除
glyphicon eye open
并将其替换为
glyphicon ok