jQuery | serialize()及其示例

serialize()方法是jQuery中的一个内置方法,用于以标准URL编码表示法创建文本字符串。这个方法可以作用于一个jQuery对象,该对象已经选择了单独的表单控件,比如input、textarea等。

null

语法:

$(selector).serialize()

参数: 此方法不包含任何参数。

返回值: 此方法返回选定元素的对象字符串。

下面的示例演示了jQuery中的serialize()方法:

例子:

<!DOCTYPE html>
< html >
< head >
< title >serialize Method</ title >
< script src =
</ script >
<!-- jQuery code to show the working of this method -->
< script >
$(document).ready(function() {
$("button").click(function() {
$("#d").text($("form").serialize());
});
});
</ script >
< style >
#d1 {
width: 300px;
height: 100px;
padding: 20px;
border: 2px solid green;
margin-bottom: 10px;
}
</ style >
</ head >
< body >
< div id = "d1" >
< form action = "" >
Site Name:
< input type = "text" name = "SiteName" value = "GeeksforGeeks" >
< br >
< br > Contributor name:
< input type = "text" name = "ContributorName" value = "geeks" >
< br >
</ form >
<!-- click on this button -->
< button >Click here!</ button >
</ div >
< div id = "d" ></ div >
</ body >
</ html >


输出: serialize method

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享