- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下表单
,我想以表格形式显示,它允许用户输入一个金额,该金额不应超过1500
。当 input
字段的值发生变化时,它会检查该值并显示一条错误消息
。
问题在于,当显示错误消息
时,包含input
的宽度列发生了变化(如您在代码片段中所见)。 在搜索中,我发现类 invalid-feedback
具有导致宽度变化的 display: block;
属性。但是我找不到解决这个问题的方法。如何解决这个问题?
$('input').change(function() {
if ($(this).val() > 1500) {
$(this).removeClass('is-valid').addClass("is-invalid");
$($(this).attr('data-msgbox')).html('Amount should not be more than Rs. 1,500');
} else {
$(this).removeClass('is-invalid').addClass("is-valid");
}
});
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="table-responsive">
<table class="table table-borderless table-hover cs-table">
<caption class="cs-content">Fee Particulars and Amount</caption>
<thead class="cs-title">
<tr>
<th scope="col">#</th>
<th scope="col">Particulars</th>
<th scope="col">Amount</th>
</tr>
</thead>
<tbody class="cs-content">
<tr>
<th scope="row">1.</th>
<td>Tution Fee</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="tution" id="tutionFee" placeholder="Tution Fee" data-input-length="3,4" data-msgbox="#tutionFeeMsg">
<div class="invalid-feedback" id="tutionFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">2.</th>
<td>Admission/Re-admission</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="admission" id="admissionFee" placeholder="Admission/Re-admission Charge" data-input-length="3,4" data-msgbox="#admissionFeeMsg">
<div class="invalid-feedback" id="admissionFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">3.</th>
<td>Library Charge</td>
<td>
<div class="form-group m-0 w-100">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="library" id="libraryFee" placeholder="Library Charge" data-input-length="2,3,4" data-msgbox="#libraryFeeMsg">
<div class="invalid-feedback" id="libraryFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">4.</th>
<td>Examination Charge</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="examination" id="examinationFee" placeholder="Examination Fee" data-input-length="2,3,4" data-msgbox="#examinationFeeMsg">
<div class="invalid-feedback" id="examinationFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">5.</th>
<td>Electricity Charge</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="electricity" id="electricityFee" placeholder="Electricity Charge" data-input-length="2,3,4" data-msgbox="#electricityFeeMsg">
<div class="invalid-feedback" id="electricityFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">6.</th>
<td>Development Charge</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="development" id="development" placeholder="Development Charge" data-input-length="2,3,4" data-msgbox="#developmentMsg">
<div class="invalid-feedback" id="developmentMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">7.</th>
<td>Fine</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="fine" id="fine" placeholder="Fine" data-input-length="2,3,4" data-msgbox="#fineMsg">
<div class="invalid-feedback" id="fineMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">8.</th>
<td>Back Dues</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="dues" id="dues" placeholder="Back Dues" data-input-length="2,3,4" data-msgbox="#duesMsg">
<div class="invalid-feedback" id="duesMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">9.</th>
<td>Late Fine</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="late_fine" id="lateFine" placeholder="Late Fine" data-input-length="2,3,4" data-msgbox="#lateFineMsg">
<div class="invalid-feedback" id="lateFineMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">10.</th>
<td>Miscellaneous</td>
<td>
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="miscellaneous" id="miscellaneous" placeholder="Miscellaneous" data-input-length="2,3,4" data-msgbox="#miscellaneousMsg">
<div class="invalid-feedback" id="miscellaneousMsg"></div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
谢谢!!
最佳答案
为了固定包含 input
的列宽,将此 width-fixed
类分配给包含 的每个
字段并添加此 CSS 规则 td
input.width-fixed{ width:300px!important;}
,您可以更改 width
值以满足您的要求
$('input').change(function() {
if ($(this).val() > 1500) {
$(this).removeClass('is-valid').addClass("is-invalid");
$($(this).attr('data-msgbox')).html('Amount should not be more than Rs. 1,500');
} else {
$(this).removeClass('is-invalid').addClass("is-valid");
}
});
.width-fixed{
width:300px!important;
}
@media (max-width:480px){
.width-fixed{
width:300px!important;
overflow-x: scroll!important;
}
}
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="table-responsive">
<table class="table table-borderless table-hover cs-table">
<caption class="cs-content">Fee Particulars and Amount</caption>
<thead class="cs-title">
<tr>
<th scope="col">#</th>
<th scope="col">Particulars</th>
<th scope="col">Amount</th>
</tr>
</thead>
<tbody class="cs-content">
<tr>
<th scope="row">1.</th>
<td>Tution Fee</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="tution" id="tutionFee" placeholder="Tution Fee" data-input-length="3,4" data-msgbox="#tutionFeeMsg">
<div class="invalid-feedback" id="tutionFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">2.</th>
<td>Admission/Re-admission</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="admission" id="admissionFee" placeholder="Admission/Re-admission Charge" data-input-length="3,4" data-msgbox="#admissionFeeMsg">
<div class="invalid-feedback" id="admissionFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">3.</th>
<td>Library Charge</td>
<td class="width-fixed">
<div class="form-group m-0 w-100">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="library" id="libraryFee" placeholder="Library Charge" data-input-length="2,3,4" data-msgbox="#libraryFeeMsg">
<div class="invalid-feedback" id="libraryFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">4.</th>
<td>Examination Charge</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="examination" id="examinationFee" placeholder="Examination Fee" data-input-length="2,3,4" data-msgbox="#examinationFeeMsg">
<div class="invalid-feedback" id="examinationFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">5.</th>
<td>Electricity Charge</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="electricity" id="electricityFee" placeholder="Electricity Charge" data-input-length="2,3,4" data-msgbox="#electricityFeeMsg">
<div class="invalid-feedback" id="electricityFeeMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">6.</th>
<td>Development Charge</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="development" id="development" placeholder="Development Charge" data-input-length="2,3,4" data-msgbox="#developmentMsg">
<div class="invalid-feedback" id="developmentMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">7.</th>
<td>Fine</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="fine" id="fine" placeholder="Fine" data-input-length="2,3,4" data-msgbox="#fineMsg">
<div class="invalid-feedback" id="fineMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">8.</th>
<td>Back Dues</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="dues" id="dues" placeholder="Back Dues" data-input-length="2,3,4" data-msgbox="#duesMsg">
<div class="invalid-feedback" id="duesMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">9.</th>
<td>Late Fine</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="late_fine" id="lateFine" placeholder="Late Fine" data-input-length="2,3,4" data-msgbox="#lateFineMsg">
<div class="invalid-feedback" id="lateFineMsg"></div>
</div>
</div>
</td>
</tr>
<tr>
<th scope="row">10.</th>
<td>Miscellaneous</td>
<td class="width-fixed">
<div class="form-group m-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-rupee-sign"></i></div>
</div>
<input type="number" class="form-control" name="miscellaneous" id="miscellaneous" placeholder="Miscellaneous" data-input-length="2,3,4" data-msgbox="#miscellaneousMsg">
<div class="invalid-feedback" id="miscellaneousMsg"></div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
关于javascript - 将 ":invalid"样式应用于表单控件时出现表格列宽问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52244137/
我正在尝试向 iOS 应用商店提交更新。我要从 Buzztouch 应用程序转到 Sprite Kit 应用程序。我能够存档 Xcode 项目并提交它。该应用程序的状态为“上传已收到”,但大约一分钟后
我收到了这个奇怪的警告。我不确定是什么原因造成的。 .dia文件扩展名应该表示核心有向图图形文件。我没有添加,应用程序几乎没有用户界面。 最佳答案 我对这个答案并不满意,但我认为它可以帮助人们,直到找
下面用作 Uri 参数的程序集限定字符串在 XAML 中工作,但在代码中使用时会出现错误。 我尝试了各种 UriKind,结果都相同。我该如何解决这个问题? [Test] public void La
我正在开发一个 Angular 应用程序,目的是将其部署到移动设备和 Web 浏览器上。设置表单样式以显示无效输入时,我应该定位 Angular“ng-invalid”类还是 HTML5“:inval
我有一个在 Google App Engine 上运行的应用程序,它是 Android 应用程序的后端。它基本上是 Android 应用程序和在我自己的服务器上运行的 MySQL 数据库之间的桥梁。
我的代码是这样的: func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle,
I need to encrypt using Python with the A256GCM algorithm, and getting back a JWT that I need to
无法成功编译webpack并生成bundle.js文件。据我了解,我的 src_dir 和 dist_dir 变量能够指向正确的路径,但在尝试编译时我仍然始终收到两个错误之一。 配置对象无效。 Web
因此,当我在 postgres 上运行 regexp_matches 时收到一条错误消息,并且无法弄清楚如何通过它。它似乎在 regex101 等 reg_exp 测试站点上运行良好,但不幸的是在实际
这些是我正在使用的导入: import com.novell.ldap.*; import java.io.UnsupportedEncodingException; 我正在尝试进行一个非常简单的密码
在记录器函数的简写情况下,Pylint 提示 Invalid constant name "myprint"(invalid-name)。 # import from utils import get
我试图创建一个HTML输入标签,该标签仅接受以2种格式之一输入的数字,并拒绝所有其他输入。 我只想接受以下格式的数字,包括破折号: 1234-12 和 1234-12-12 注意:不是日期,而是合法的
我一直在尝试使用 Bootstrap 的表单样式处理 AngularJS 的电子邮件验证,并遇到了这个 CSS block 。 input:focus:required:invalid, textar
我正在编写一个程序,以确保我了解如何在 C 中正确实现单向链表。我目前正在哈佛的 CS50 类(class)中学习,并且使用本教程,因为 CS50 人员不解释链接详细列出数据结构:https://ww
此问题与询问同一消息的另一个问题不重复,但在另一个上下文中。这个问题的上下文只是关于上传截图图像和获取消息。 今天,我在将图片上传到 App Store Connect 时收到一条新消息: Inval
我的代码似乎运行良好,但当我滑动以删除 UITableView 中的一行时,应用程序崩溃并显示以下内容: 错误 LittleToDoApp[70390:4116002] *** Terminating
当我尝试发送语音消息时,总是收到无效的url错误。我正在使用Whisper将音频转换为文本,但由于某种原因,我似乎无法将文件传递给Whisper。当我在Java脚本中使用它而不是在TypeScrip中
我正在尝试在 flutter 上对 http 客户端进行单元测试。在模拟 http 和我的存储库类之后: void main() { MockHttpCLient mockHttpCLient;
我正在使用 pandoc 作为一个库,相关的代码片段是: module Lib ( latexDirToTex, latexToTxt ) where import qualified
我正在开发一个(相对简单的)Rails应用程序。我正在使用Devise gem处理用户 session 。每当我导航到localhost:3000/users/sign_in时,我都会看到Devise
我是一名优秀的程序员,十分优秀!