Love beautiful code? We do too.
.serialize(): Lấy giá trị các thành phần form, mã hóa các giá trị này thành giá trị chuỗi. Giá trị sẽ được hiển thị theo các cặp cách nhau bởi ký tự "&": name1=value1&name2=value2&...
Đã được thêm vào từ phiên bản 1.0
.serialize()
$('form').serialize();
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
function showValues() {
var str = $("form").serialize();
$("#result").text(str);
}
$("input[type='radio']").on("click",showValues);
showValues();
});
</script>
</head>
<body>
<form>
<input type="radio" name="radio" value="Male" checked="checked" id="male" />
<label for="male">Male:</label>
<input type="radio" name="radio" value="Female" id="female" />
<label for="female">Female:</label>
</form>
<p id="result"></p>
</body>
</html>
Hiển thị trình duyệt:
Khi click chọn vào radio ta đã lấy được giá trị của các thành phần này thay đổi thông qua cặp giá trị name=value.
Hoclaptrinh.vn © 2017
From Coder With
Unpublished comment
Viết câu trả lời