javascript 在javascript中单击另一个按钮后激活按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22349219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:58:25  来源:igfitidea点击:

activate button after another button click in javascript

javascriptjqueryhtml

提问by Karthika

I have three button are after clicking on one button,second has to access the click and then the third .when i click on the third button it should not work

我有三个按钮是点击一个按钮后,第二个必须访问点击,然后第三个。当我点击第三个按钮时,它不应该工作

<input type="button" value="button" id="one" onclick="show()" action="">
<input type="button" value="button" id="two" onclick="show1()">
<input type="action" value="button" id="three">

<script>
function show{ 
}
</script>

回答by Abhay Prince

Initially disable second and third button using :

最初使用以下方法禁用第二个和第三个按钮:

<input type="button" value="button" id="two" onclick="show1()" disabled="disabled"/>
<input type="action" value="button" id="three" disabled="disabled"/>

And Use this code :

并使用此代码:

function show()
{
    document.getElementById('two').removeAttribute('disabled');
}
// And Same For Second Button Click
function show1()
{
    document.getElementById('three').removeAttribute('disabled');
}

回答by Afzaal Ahmad Zeeshan

jQuery would be better here:

jQuery 在这里会更好:

$('#one').click(function () { // on a click on the button with id 'one'
  $('#two').trigger('click');// trigger the click on second, and go on 
}

Using this method you can trigger events on other elements using an event on a particular element!

使用此方法,您可以使用特定元素上的事件触发其他元素上的事件!

回答by halkujabra

    <script>
    function show(){ 
$('#button1').attr('disabled',false);
$('#button2').attr('disabled',false);

    }
    function show1(){
$('#button2').attr('disabled',false);
    }
    </script>

回答by knightsb

you can use Jquery to bind an event to the click. and there do what you want:

您可以使用 Jquery 将事件绑定到单击。然后做你想做的:

$('#ButtonID').bind('click',function(){
   $('#ButtonID2').show(); 
    //or
   $('#ButtonID1').removeAttr('disabled');//if you want it be shown but not enabled
});

this is for disableing the buttons:

这是用于禁用按钮:

 $('#ButtonID').attr('disabled','disabled');

回答by Anoop Joshi

Are you looking for this

你在找这个吗

$("input").click(function(){
 $("input").attr('disabled','disabled');
$(this).next().removeAttr('disabled');

});

Demo

演示