简体   繁体   中英

how to run javascript when sql has loaded

I am using some github jquery code https://github.com/viralpatel/jquery.shorten to automatically shorten a paragraph and add a read more button, so i made the div element and it works fine when i use normal text, but i tried to add some sql (inside php) to show a value of something in a sql table, but when i load the page it just says "more" and when i click it, it loads the value from the sql, but it is supposed to just shrink the value and then when you click more it is supposed to show the rest instead it shows nothing and then when you click "more" it shows all of it, I am really stuck on this, have been trying to find an answer already for a few days.

example code

<div class="example">
    <?php echo $sql_query; ?>
</div>

<script>
$(document).ready(function() {

        $(".example").shorten({showChars: 100});
     });
</script>

I figured out why it was causing such problems, I had comments inside the div element before the php echo, so it was counting the comments as chars, so when i removed the comments it all worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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