如何禁用靴子模式对话框中的按钮?

问题描述:

目前能够用下面的代码如何禁用靴子模式对话框中的按钮?

modal.find('.modal-body #transfer').prop('disabled', true) 

但上面没有为按钮工作,可以禁用输入字段。我的按钮代码如下

<button id="transfer" type="button" class="btn bg-orange btn-flat" onclick="transfer()" >Transfer</button> 
+0

您对按钮的确切命令是什么?它应该使用'.prop(“disable”,true)'。 – David

+0

按钮通过onlick执行一个功能。这些都是我的代码。前两个工作,因为它处理输入字段和下拉菜单,但第三个是按钮,出于某种原因不起作用。 modal.find('。modal-body #rotransfer')。prop('disabled',true) modal.find('。modal-body #reasonriskowner')。prop('disabled',true) modal.find '.modal-body #transfer')。prop(“disabled”,true) – Shuyaib

+0

Ok nvm。它现在奏效了,因为禁用应该使用双引号而不是单引号。 – Shuyaib

的问题是使用单引号禁用命令。应该是双引号。

您应该使用按钮的disabled属性。使用attr()函数尝试以下代码。

modal.find('.modal-body #transfer').attr('disabled', true); 
+0

这正是我正在使用的。 – Shuyaib

+0

在给定的代码中,你添加了'prop'而没有'attr' – Thusitha

在这里,你去了一个解决方案

$('.modal').find('button#transfer').prop('disabled', 'disabled'); 

例解

$('.modal').find('button#transfer').prop('disabled', 'disabled');
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
<!-- Trigger the modal with a button --> 
 
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> 
 

 
<!-- Modal --> 
 
<div id="myModal" class="modal fade" role="dialog"> 
 
    <div class="modal-dialog"> 
 

 
    <!-- Modal content--> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
 
     <h4 class="modal-title">Modal Header</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
     <p>Some text in the modal.</p> 
 
     </div> 
 
     <div class="modal-footer"> 
 
     <button id="transfer" type="button" class="btn bg-orange btn-flat" onclick="transfer()" >Transfer</button> 
 
     </div> 
 
    </div> 
 

 
    </div> 
 
</div>

希望这会帮助你。

使用下面的代码以禁用按钮 -

$('#transfer').prop('disabled',true);