如何使用javascript/jquery在任何文本框中查找输入或不输入的值
How to find values entered or not in any of the textboxes using javascript/jquery
我有三个ID的ppl1,pp2和ppl3。
我可以通过制作一些 javascript 函数来查找在这些文本框中输入的任何值
,如下所示$(document).ready(function () {
$("#ppl1").change(function () {
或
$(document).ready(function () {
$("#ppl2").change(function () {
或
$(document).ready(function () {
$("#ppl3").change(function () {
现在我需要检查是否已输入任何文本框。也就是说,在上述函数中使用一些逻辑 OR (||)。
希望这可以简单地完成,但即使长时间谷歌搜索,我也无法得到确切的东西。
// Bind keyup event on the input
$('input:text').keyup(function() {
// If value is not empty
if ($(this).val().length != 0) {
console.log("input with ID: " + $(this).attr('id') + " has value")
} else {
console.log("input with ID: " + $(this).attr('id') + " has no value")
}
}).keyup(); // Trigger the keyup event, thus running the handler on page load
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input name="ppl1" id="ppl1" />
<input name="ppl2" id="ppl2" value='123' />
<input name="ppl3" id="ppl3" />
您可以使用.keyup()
$(function(){ // This is equal to "$(document).ready(function () {"
// $("[id^='ppl']") This selector works as well.
$("#ppl1, #ppl2, #ppl3").on('change',function(e){
if ($(this).val().trim().length > 0)
{
// The input has changed, and there is something in it.
}
});
});
相关文章:
- 需要URL模板占位符查找和替换功能的输入
- Javascript文本框-查找最低的输入和填充
- 在 jquery 中的 TR 中查找 td 的所有输入
- jQuery选择器,用于查找包含具有特定值的TD输入的TR
- 查找表单输入的第一个单词
- 在指定的td中查找输入字段的特定值
- 使用最接近查找文本输入的JQuery问题
- Regex以查找除输入的最后n个字符之外的匹配项
- 如何在另一个页面中查找元素,并从当前页面上的元素中输入值
- Mongoose:查找与输入类似的名称
- 使用jQuery查找输入字段
- 查找表单的哪些特定部分在输入时发生了更改
- 在javascript中的page ready中查找输入值修改的来源
- 如何从许多其他输入中查找触发键关闭事件的特定输入框
- 如何使用Javascript查找一系列隐藏输入字段的索引
- eBay 查找 API findItemsByKeywords 返回“输入 URL 为标头 X-EBAY-SOA-OPE
- 在集合中查找空的输入元素 - jQuery
- 如何查找输入标签中的字符数
- 如何将我的 Google 地图功能从自动查找我的位置更改为让我输入一个位置
- 通过在文本框中输入查找属性值并获得父属性值