开发者

jQuery .click() function - linking between two .click() functions (on seperate pages) and bringing up the related content

Okay, so I've got two .click() functions on two pages, which both work fine, no problem there. I need to be able to link from within one of the .click() functions to the other. How should the links be written or is the .click() function not right for this kind of process?? Linking to the page is fine ie. other content, but I want to be able to bring up the content from, lets say, 'changeText3' when the otherpage.html loads without having to click on the link on that page.

LOL, hope that's not too confusing.

<ul id="subNav">                                
    <li><a id="changeText1">&nbsp;Link 1</a></li>
    <li><a id="changeText2">&nbsp;Link 2</a></li>
    <li><a id="changeText3">&nbsp;Link 3</a></li>
</ul>  

<div id="textBox">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tempor tincidunt varius. Cras adipiscing lacinia rhoncus. Suspendisse felis velit, dignissim scelerisque sodales vitae, hendrerit nec lorem.</p> 
    <p>Contact us <a href="contact.html">here.</a></p>
</div><!--end of textBox-->

<script type="text/javascript" src="media/js/jquery.v1.6.js"></script>
<script type="text/javascript">
    $(document).ready(function() {          
        $("#changeText1").click(function() {
            $("#textBox").html("<p>Aliquam elementum vulputate ipsum, et faucibus lorem sagittis quis.</p><p><a href='otherpage.html'>Link to relevant content</a></p>");
        });

        $("#changeText2").click(function() {
            $("#textBox").html("<p>Suspendisse potenti. Vivamus tempus fermentum leo nec tincidunt.</p><p><a href='otherpage.html'>Link to relevant content</a></p>");
        });

        $("#changeText3").click(function() {
            $("#textBox").html("<p>Vivamus id convallis augue. Nam scelerisque ante non开发者_JAVA技巧 sem tempor feugiat. Phasellus leo leo, malesuada in faucibus a, pellentesque id dui.</p><p><a href='otherpage.html'>Link to relevant content</a></p>");
        });
    });
</script>


If you are literally linking between two different pages, there's no way for the scripts on either page to know anything about the other. Consider each page a blank slate. You have to pass information between the pages somehow and handle the content update on the new page.

You could put the code currently inside your click functions in a non-anonymous function and call that when the linked page loads, using a get parameter to identify which of the links was clicked and updating the content appropriately. (newpage.html?clicked=link1)

I suspect you're going about this in the wrong way though it's not clear what you're trying to do

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜