Home > Web Front-end > JS Tutorial > How to get the value in the hidden field with jquery

How to get the value in the hidden field with jquery

青灯夜游
Release: 2021-11-19 11:30:57
Original
4018 people have browsed it

Jquery method to get the value in the hidden domain: 1. Use the "$("input:hidden")" statement to get the hidden domain node; 2. Use the val() method to get the value in the hidden domain, the syntax is " hidden domain node.val()".

How to get the value in the hidden field with jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Hidden fields

<input type="hidden" name=""  value="">
Copy after login

Hidden fields are invisible to users on the page. The purpose of inserting hidden fields in the form is to collect or send information to facilitate the users. Used by programs that process forms. When the viewer clicks the send button to send the form, the hidden field information is also sent to the server.

How to get the value in the hidden field with jquery?

In jquery, you can use the val() method to get the value in the hidden field.

val() method returns or sets the value of the selected element.

The value of the element is set through the value attribute. This method is mostly used for input elements.

If this method does not set parameters, it returns the current value of the selected element.

Get value syntax:

$(selector).val()
Copy after login

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script src="js/jquery-1.10.2.min.js">
		</script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					var value = $("input:hidden").val();
					alert(value);
				});
			});
		</script>
	</head>
	<body>
		<input type="text" value="hello" /><br><br>
		<input type="hidden" value="欢迎来到PHP中文网" />
		<button>获取隐藏域的值</button>
	</body>
</html>
Copy after login

How to get the value in the hidden field with jquery

Related video tutorial recommendation: jQuery tutorial(video)

The above is the detailed content of How to get the value in the hidden field with jquery. For more information, please follow other related articles on the PHP Chinese website!

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