Jquery uses if to determine that the tag content is not empty: 1. When the tag has an id attribute set, use [$("#id")] to get the tag; 2. For tags that do not have an id set , use a similar jsoup expression to obtain, the code is [var nameVal = $("#aaa input[]].
The operating environment of this tutorial: Windows7 system , jquery3.2.1 version, Dell G3 computer.
Recommendation: jquery video tutorial
##How to use if to determine that the tag content is not empty in jquery:
Problem description
It is necessary to determine whether the user selects an option in the list or enters custom content and whether it is not empty. If it is not empty, proceed to the next step. , otherwise prompt the user.<p id="namep">姓名: <input type="text" class="name"></input> </p>
Solution
Get the content of the specified tag and perform null processing// $(document).ready(function(){ ... }); // 标签有设置 id 属性时,使用 $("#id") 获取标签即可 // 对于没有设置 id 的标签,使用类似jsoup表达式来获取 var nameVal = $("#aaa input[class='name']").val(); if(nameVal == null || nameVal == "" || nameVal == undefined){ alert("name 输入框为空"); }
text() - Set or return the selected element The text content
html() - Sets or returns the content of the selected element (including HTML tags)
val() - Set or return the value of the form field
Related free learning recommendations: javascript learning tutorial
The above is the detailed content of How to use if in jquery to determine if the tag content is not empty. For more information, please follow other related articles on the PHP Chinese website!