从另一个窗体到另一个窗体禁用按钮的问题

Issue in disabling button from another form to another

本文关键字:另一个 窗体 问题 按钮      更新时间:2023-09-26

我正在制作一个单页网站,并使用jquery显示和隐藏表单切换。

我想做的是在用户点击第二个链接后,它会显示,前两个按钮将无法,用户点击第三个链接后,它将无法所有的按钮。如果用户点击第一个链接,它将禁用twothree按钮。

我的问题是我点击第二个链接后,所有的按钮都无法点击后的第三个链接相同。

电流输出:http://jsfiddle.net/GZSH6/92/

脚本:

    $('#one').prop('disabled', false);
    $('#two').prop('disabled', true);
    $('#three').prop('disabled', true);

$('.one').click(function(){
    $('#one').prop('disabled', false);
    $('#two').prop('disabled', true);
    $('#three').prop('disabled', true);
});
$('.two').click(function(){
    $('#one').prop('disabled', false);
    $('#two').prop('disabled', false);
    $('#three').prop('disabled', true);
});
$('.three').click(function(){
    $('#one').prop('disabled', false);
    $('#two').prop('disabled', false);
    $('#three').prop('disabled', false);
});

首先,不应该有具有相同ID的HTML元素。这会造成问题。其次,我建议使用。attr()(属性)方法,而不是。prop()。

我用这些变化修改了你的代码,它正在工作,虽然你可能想要审查你的方法,只有一个页面上的每个按钮的副本,或者,如果你想让他们重复每个div,然后设置他们的属性固定,因为他们似乎永远不会改变。

我已经包含了下面这些修改的代码,但我也用这些更改fork了您的JSFiddle。你可以在这里查看:http://jsfiddle.net/QTMR5/1/.

<a href="javascript:void(0)" class="show-page one" data-page="first">First</a>
<a href="javascript:void(0)" class="show-page two" data-page="second">Second</button>
<a href="javascript:void(0)" class="show-page three" data-page="third">Third</a>
<div class="container">
    <div class="page first">
        <div class="row">
            <center>
                First Page<br />
                <button class="btnd btnd-default" id="firstone">Personal Info</button>&nbsp;<br />
            <button class="btnd btnd-default" id="firsttwo">Educational Info</button>&nbsp;<br />
            <button class="btnd btnd-default" id="firstthree">Employment Info</button>
            </center>
         </div>
    </div>
    <div class="page second hide">
        <div class="row">
            <center>
                Second Page <br />
                 <button class="btnd btnd-default" id="secondone">Personal Info</button>&nbsp;<br />
            <button class="btnd btnd-default" id="secondtwo">Educational Info</button>&nbsp;<br />
            <button class="btnd btnd-default" id="secondthree">Employment Info</button>
            </center>
         </div>
    </div>
    <div class="page third hide">
        <div class="row">
            <center>
                Third Page <br />
                 <button class="btnd btnd-default" id="thirdone">Personal Info</button>&nbsp;<br />
            <button class="btnd btnd-default" id="thirdtwo">Educational Info</button>&nbsp;<br />
            <button class="btnd btnd-default" id="thirdthree">Employment Info</button>
            </center>
         </div>
    </div>

$(document).ready(function () {
    $('#firstone').attr("disabled", false);
    $('#firsttwo').attr('disabled', true);
    $('#firstthree').attr('disabled', true);
$('.one').click(function(){
    $('#firstone').attr('disabled', false);
    $('#firsttwo').attr('disabled', true);
    $('#firstthree').attr('disabled', true);
});
$('.two').click(function(){
    $('#secondone').attr('disabled', false);
    $('#secondtwo').attr('disabled', false);
    $('#secondthree').attr('disabled', true);
});
$('.three').click(function(){
    $('#thirdone').attr('disabled', false);
    $('#thirdtwo').attr('disabled', false);
    $('#thirdthree').attr('disabled', false);
});
var value = 0, progress;
function progressBar() {
    progress = setInterval(function () {
        var $bar = $('.bar');
        if (value >= 100) {
            clearInterval(progress);
            $('.progress').removeClass('active');
            $(".show-page[data-page=Profile]").trigger("click");
        } else {
            value += 10;
            $bar.width(value * 7);
        }
        $bar.text(value + "%");
    }, 800);
};
$(document).ready(function () {
    if (typeof (Storage) !== "undefined" && localStorage.getItem('pageToShow')) {
        var pageToShow = localStorage.getItem('pageToShow');
        $('.page').addClass('hide');
        $('.' + pageToShow).removeClass('hide');
    };
    $('.show-page').click(function () {
        var pageToShow = $(this).data('page');
        if (pageToShow == "progBar") {
            value = 0;
            $('.bar').width(0);
            $('.progress').addClass('active');
            progressBar();
        } else {
            clearInterval(progress);
        };
        $('.page').addClass('hide');
        $('.' + pageToShow).removeClass('hide');
        if (typeof (Storage) !== "undefined") {
            localStorage.setItem('pageToShow', pageToShow);
        };
    });
});
});