javascript - 选择所有具有名称属性的输入包含子字符串 - jQuery
问题描述
我想选择所有名称属性以 . 结尾的输入*Name
。
我有 6 个输入类型文本,名称为:
- 设备名称
- 个人资料名称
- 名称
- 俘虏姓名
- 流量名称
- 会话名称
HTML
<input class="form-control" type="text" name="deviceName">
<input class="form-control" type="text" name="profileName">
<input class="form-control" type="text" name="ssidName">
<input class="form-control" type="text" name="captiveName">
<input class="form-control" type="text" name="trafficName">
<input class="form-control" type="text" name="sessionName">
我试图防止在这 5 个输入上输入任何空格
我试过了
$("input[name='*Name']").keyup(function() {
this.value = this.value.replace(/\s/g, '');
});
我的选择似乎没有任何影响。
解决方案
我认为您使用了正确的选择器,但在错误的位置。
你需要像这样使用它$("input[name*='Name']")
请参阅 jquery 文档的链接。https://api.jquery.com/attribute-contains-selector/
推荐阅读
- java - Google 数据存储区实体不返回 ID。实体 ID 为空
- python - 尝试获取训练数据集的值时出错
- javascript - 如何在 React 中修复 JSX 中的渲染错误 createElement()
- tensorflow - tf.keras fit() 方法不打印预期反馈
- python - 如果不再支持 OpenCV 2.4,如何安装?
- c - 找不到 glib2-0 库的实现(sudo apt-get install libglib2.0-dev)
- c++ - free():下一个大小无效(正常)和 munmap_chunk():C 中的指针无效
- java - 找不到参数的方法 implementation() [org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50]
- python - Django ORM 优化 - 按计数以及注释过滤器的最后一个条目进行注释
- bash - Bash 命令对具有多列的文件中的特定数字列求和