开发者

How to change visibility in dynamically generated content Javascript and PHP

Hi Everyone so here's the problem, I think it's mostly a little problem with my lack of knowledge in Javascript but here's what I did:

JS Code:

function mostrarResul(idFold, Id)
{

    if($(idFold).css(visibility) == "none")
    {
        $(idFold).css(visibility, inline);
        $(Id).detach();
        $(Id).append("<a id='"+Id+"' class='showmore' onclick='mostrarResul("+idFold+", "+Id+")'>ver menos</a>");
    }else
    {
        $(idFold).css(visibility, none);
        $(Id).detach();
        $(Id).append("<a id='"+Id+"' class='showmore' onclick='mostrarResul("+idFold+", "+Id+")'>ver m&aacute;s</a>");
    }

}

PHP Code:

$idFolder = $item[_folder_name];
                    $idFolder = strtolower($idFolder);
                    $idFolder = str_replace(" ", "_", $idFolder);
                    echo "<div class='result'>";
                    echo "<div class='item'>
                    <label><a onclick='mostrarResul($idFolder, $id)'>".$item[_folder_name]."</a></label>";
                    $news = process_all("SELECT * FROM _tips WHERE _folder = '$item[_folder_name]' ORDER BY _date_create LIMIT 0,20");
                    echo "<div class='itemNews' id='".$idFolder."' style='display:none'>";
                    echo "<ul>";
                    if ($news) foreach( $news as $开发者_如何学编程n)
                    {
                        echo "<a href='/consejos-recomendaciones/".$n[_permalink]."'>".$n[_subject]."</a><br/>";
                    }
                    echo "</ul";
                    echo "</div>";
                    echo "<a id='".$id."' class='showmore' onclick='mostrarResul($idFolder, $id)'>ver m&aacute;s</a>
                    </div>";
                    echo "</div>";
                    $id += 1;

Ok so the JS code is supposed to change the visibility attribute depending on it's current state and detach & append code depending on the same things, my real problem is when sending the variables to the JS and manipulating them, any tips??

Hi again, Someone said before that I could do this using Jquery.js and I wanted to ask how???, I'm already using jquery for other things and wanted to now how to use it when I'm creating the Id for the tags???

Solved. The other thing is, do you guys now what function in PHP 5.2 returns a string of a length that I want, example

String Val= "Hello everyone";

(function to manipulate string)

and the new string val is "Hello".


So, your problem (that I see) is that everything inside .css() should be in quotes. I assume you're using jQuery? If not already, you need to include it in your page head, like this:

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>

then everything you write in jQuery should not be without quotes:

 $(idFold).css(visibility, inline);

but should be like this:

 $(idFold).css('visibility', 'inline');

Also, the hidden property not "none" is the correct property for visibility

http://www.w3schools.com/cssref/pr_class_visibility.asp has more info on it.


The answer to your last question is substr. http://php.net/manual/en/function.substr.php So in your case, it would be

$var = "Hello everyone";
$new_var = substr($var, 0, 5);
echo $var . ' - ' . $new_var;

Output would be: Hello everyone - Hello

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜