简体   繁体   English

Ajax更新HTML元素的CSS

[英]Ajax update css of HTML elements

I want display and hide HTML div with ajax, 我想用ajax显示和隐藏HTML div,

Situation: 情况:

progressbar('on');

very_long_function(); 

progressbar('off');

I want display div when working very_long_function(); 我要在工作very_long_function();时显示div very_long_function(); , bUt when finish working I want hide div ,但是完成工作后我要隐藏div

Progress bar function: 进度条功能:

function progressbar($status){

    if($status == "on"){


        echo "
                <script> 
                        $(document).ready(function() {   function() { 
                        $('#load').css('display','inline');

                        }); 
                </script>
            ";
    } 
    else{

        echo "
                <script> 
                        $$(document).ready(function() {   function() { 
                        $('#load').css('display','none');

                        }); 
                </script>
            ";
    }
}

Problem is that div not showing when very_long_function(); 问题是,当very_long_function();时div不显示very_long_function(); working, maybe is possible to solve this priblem with AJAX or jQuery 工作,也许可以用AJAX或jQuery解决这个问题

HTML 的HTML

<div id="load" style="display: none;"><img src="loading_baras.gif" style="width: 550px; height: 10px; margin-top: -10px"></div>

Are sure that you included jquery lib for using it . 确保您包括使用它的jquery lib。 Also there is no double $$ in jquery. jQuery中也没有double $$。 Please give the html and after we will correct it. 请提供html,我们将对其进行更正。

I think, that you architecture is wrong. 我认为您的架构是错误的。 You have to user JS for it. 您必须为此使用JS。

Like next: 像下一个:

    $(function(){
       $('#load').css('display','inline');

       $.post('/very_long_function.php', {url: 'http://www.google.com'}, function(result){
           alert(result);
           $('#load').css('display','none');
       }); 
    });

PHP: very_long_function.php PHP: very_long_function.php

$url = $_POST['url'];
$result = very_long_function($url);
echo $result;
die;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM