简体   繁体   English

EventHandler:单击按钮1时启用按钮2

[英]EventHandler: Enable Button 2 when clicked on Button 1

I have two buttons in my HTML page, and I would like to incorporate a functionality that on clicking button "Show Fields", the Make Edits button should get enabled. 我的HTML页面中有两个按钮,并且我希望合并一项功能,即单击“显示字段”按钮时,应启用“进行编辑”按钮。 Currently, the button Make Edits is diabled. 当前,“编辑”按钮被禁用。 My HTML code is 我的HTML代码是

<input type="submit" class="btn btn-info" name="showname" value="Show Fields" onclick ='editFunc()' style="margin-right: 5px;"/>
<input type="submit" class="btn btn-info" id = "makeEdits"  name="makeEdits" value="Make Edits" disabled ='disabled' style="margin-right: 5px;"/>

I have written Jquery for event handling : 我已经编写了用于事件处理的Jquery:

function editFunc(){document.getElementById('makeEdits').disabled = false;}

The Make Edits button gets enabled for a second and then goes back to its normal state : ie it becomes disabled. 进行“编辑”按钮一秒钟,然后返回其正常状态:即变为禁用状态。

Can anyone please help. 谁能帮忙。

If you are using jquery you don't need to use onClick, instead you give your button an id (in this case showName ): 如果您使用的是jquery,则无需使用onClick,而只需为按钮指定一个id(在本例中为showName ):

<input type="button" class="btn btn-info" name="showname" value="Show Fields" id="showName" style="margin-right: 5px;"/>

The you can do: 您可以执行以下操作:

$("#showName").on('click', function(){
    $('#makeEdits').prop('disabled', false);
});

Here's the JSFiddle 这是JSFiddle

Just a sample and simple code: 只是一个示例和简单的代码:

$("#activation_btn").on('click', function(){
    if($("#edit_btn").is(':disabled'))
        $("#edit_btn").prop('disabled', false); //$("#edit_btn").removeAttr('disabled');
    else
        $("#edit_btn").prop('disabled', true); //$("#edit_btn").addAttr('disabled');
});

You are clicking a Submit button. 您正在单击“提交”按钮。 This will call the js code you have, and then immediately post back to the server and refresh the page. 这将调用您拥有的js代码,然后立即将其发布回服务器并刷新页面。 This is why the button is disabled again so quickly - the page is back to its original state... 这就是为什么按钮再次被如此快速禁用的原因-页面返回到其原始状态...

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

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