开发者

Using Javascript to hide/show all text

开发者 https://www.devze.com 2023-03-12 05:53 出处:网络
I have an ASP page that retrieves text from a database but the formatting looks awkward because there\'s a lot of text and it stretches the page until the end. I\'m looking for a solution in javascrip

I have an ASP page that retrieves text from a database but the formatting looks awkward because there's a lot of text and it stretches the page until the end. I'm looking for a solution in javascript that will condense this text into a few lines and have an option 开发者_JS百科to show all once a button is clicked. I'm completely new to embedding javascript in pages but I think this is the simplest way to do it.


Note that your asp will, more or less, not be in contact with your Javascript. They are very separate things. That being said, you can have a flag in the C# code and then grab that value in Javascript <%= num; %>, check if it's true, and commit your code. (or better yet check on post back)

What you are trying to do sounds like you want to change the style of where the text is being put. In your javascript, grab the

paragraph area. Do this by giving the paragraph an id: and then call it in javascript and set it as a variable:

var text = document.getelementbyid('jollies');

then you can change some aspects about the text, for instance hiding it, size and other things... all under the text.style.[param]

If you want to have it shown/hidden in javascript, have a button that is not runat server to have onclick="myjavascriptfunction()" that hides the said text visiblity:hidden; and so on.


Take the result text from the ASP page and use substring to split it like so:

var asp_result
var part1 = asp_result.substring(0,25); //however far in the string you want to shorten it
var part2 = asp_result.substring(26);

var short = document.createElement('div');
var long = document.createElement('div');
short.appendChildDocument.createTextNode(part1);
long.appendChildDocument.createTextNode(part2);

var var1 document.getElementById('where_you_want_the_text');

var1.appendChild(part1);
var1.appendChild(part2);

document.getElementById('buttonID').addEventListener('click', function(long){
    if(long.getAttibute('visibility') == 'visible')
    {
        long.setAttribute('visibility', 'hidden');
    }else{
        long.setAttribute('visibility, 'visible');
    }
}, false);
0

精彩评论

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