繁体   English   中英

使用jQuery通过单击链接取消隐藏div

[英]Using jQuery to unhide a div by clicking on a link

为此,我正在使用colorbox jQuery插件http://colorpowered.com/colorbox/和一个表单。 我正在尝试使用jQuery colorbox取消隐藏包含表单的div ,并在单击以下相关链接时将其显示在colorbox中。

这是我使用的标头中的javascript:

$(document).ready(function() {
    $('#password_reset').ajaxForm({
        success: showResponse,
        clearForm: 'true'
    });

    function showResponse(responseText, statusText) {
        $('#password_reset').hide();
        $('#formStatus').html(responseText);
    };

    $().bind('cbox_open', function() {
        $('#password_reset').show();
        $('#formStatus').html('');
    });

    $(".inline").colorbox({
        width: "300px",
        height: "250px",
        inline: true,
        href: "#password_change"
    });
});

这是我应该运行我的javascript代码(上面)并取消隐藏下面的div并将其运行到colorbox中的链接:

<a href="javascript:showResponse">Password Reset</a>

这是我隐藏的div:

<div style="visibility: hidden;">
    <div id='password_change' style="padding:10px; background:#fff;">
        <strong>Change your password</strong><br /><br />
        <form id="password_reset" action="password_reset.php" method="post">
            <input type="hidden" name="Method" value="updatePassword"  />
            Password: <br />
            <input type="password" name="password1" />
            <br />
            <br />
            Verify Password: <br />
            <input type="password" name="password2" />
            <br />
            <input type="submit" value="Update" />
        </form>
        <div id="formStatus"></div>
    </div>
</div>

希望有人能告诉我如何将其完全卡住,而且我知道这是我在这里犯的一个小错误,但我不知道该如何解决。 请帮忙?

griegs的答案在那儿。 jQuery在div元素上的显示和隐藏等同于display:block; 并显示:无; 所以应该是这样的:

<div id="DIV_password_reset" style="display:none;">

$('#DIV_password_reset').show();

如果要使用可见性,请执行以下操作:

<div id="DIV_password_reset" style="visibility:hidden;">

$('#DIV_password_reset').css('visibility', 'visible');
<div id="DIV_password_reset" style="visibility: hidden;">

$('#DIV_password_reset').show();

您设置表单的可见性,而不是div。

我认为您需要使用jQuery这样的东西:

jQuery(document).ready(function(){
    jQuery('.show').live('click', function(event) {        
        $("#yourDivId").attr({style: "visibility: show;"});
    });
});​

检查jsfiddle.net

更多信息:

暂无
暂无

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

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