Home > Web Front-end > JS Tutorial > body text

jquery solution to get the value of the drop-down list to be null_jquery

WBOY
Release: 2016-05-16 18:09:18
Original
1168 people have browsed it

I wonder if any of you have encountered such a situation?
When using jquery to get the value of the drop-down list ddl, the string 'null' is returned instead of an empty value. As a result, the parameters obtained are incorrect;
Even if it is judged to be non-null in the background, it still causes Error (for example, null was spelled in when piecing together the SQL).
Let’s analyze it below:
The first situation:

Copy the code The code is as follows:



Second case:
Copy code The code is as follows:


or


We get the value like this in the program:
$("#ddlType").val()
For In the first case, if we have not made a selection, then it returns the null value "", but not the string "null";
In the second case, there are no selectable items in ddl, and there are no in the frontend If it is hardcoded or not bound in the background, if you try to get its value, the string "null" will be returned.
Solution: There is currently no better solution. We can only add judgment (!="null") in the background judgment. Obviously, this is not a good solution.
Some friends on the Internet also provided a method to modify the jquery source file and change the last sentence this.value = val; in the implementation of the val function to this.value = val || "";

If you have any good ideas, please feel free to share them! ! !
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template