[英]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.
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.