简体   繁体   English

jQuery锚标记显示问题

[英]Jquery anchor tag display problem

I am unable to show an anchor tag to display itself using .show() in Jquery or javascript. 我无法显示锚标记以在Jquery或javascript中使用.show()进行显示。 Conn Window is visible by default. 默认情况下,“ Conn窗口”是可见的。 It hides and displays the div but it is unable to do the same with anchor. 它会隐藏并显示div,但无法使用锚点执行相同操作。 I have manually tried to change it in firebug/IE dev tools and it works there. 我已经手动尝试在firebug / IE开发工具中对其进行更改,并且它在那里起作用。 It just doesn't work when I do it with jquery/javascript. 当我使用jquery / javascript时,它只是不起作用。

Here is the HTML code: 这是HTML代码:

<a href="javascript:connShow();" id="connTab" style="display:none; text-decoration:none;"></a>
<div id="connWindow">Conn Window
    <div id="closeButton" onclick="javascript:connHide();"></div>
</div>

Here is the jquery code: 这是jQuery代码:

function connHide()
{
    $('#connTab').show();
    $('#connWindow').hide();
}

function connShow()
{
    $('#connWindow').show();
    $('#connTab').hide();
}

Any help will be greatly appreciated! 任何帮助将不胜感激!

Why not bind your click events in jQuery as well 为什么不同时在jQuery中绑定点击事件

function connHide()
{
    $('#connTab').show();
    $('#connWindow').hide();
}

function connShow()
{
    $('#connWindow').show();
    $('#connTab').hide();
}

$(document).ready(function () {
    $("#contab").click(function () { 
       connShow(); 
       return false;
    });
    $("#connWindow").click(function() { 
       connHide();
    });
});

You don't need to state javascript: for onclick events. 您无需声明javascript: onclick事件。 Try changing to: 尝试更改为:

<div id="closeButton" onclick="connHide();"></div>

I would also change the first line to the following: 我还将第一行更改为以下内容:

<a href="#" onclick="connShow(); return false;" id="connTab" style="display:none; text-decoration:none;"></a>

The inline CSS display:none is overriding the mechanism jQuery uses to show and hide. 内联CSS display:none 覆盖 jQuery用于显示和隐藏的机制。

Hide the anchor programmatically instead: 而是以编程方式隐藏锚点:

HTML: HTML:

<a href="#" id="connTab" style="text-decoration:none;"></a>
<div id="connWindow">
    Conn Window
    <div id="closeButton"></div>
</div>

Script: 脚本:

$(function() { // on document load
    $('#connTab').css('display', 'none');

    // I'm going to replace your inline JS with event handlers here:
    $('#connTab').click(function() { connShow(); return false; });
    $('#closeButton').click(function() { connHide(); });
});

function connHide() {
    $('#connTab').css('display', '');
    $('#connWindow').css('display', 'none');
}

function connShow() {
    $('#connWindow').css('display', '');
    $('#connTab').css('display', 'none');
}

Hope that helps. 希望能有所帮助。

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

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