Home  >  Article  >  Web Front-end  >  Example of usage of $.extend() in jQuery_jquery

Example of usage of $.extend() in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 15:53:051361browse

The example in this article describes the usage of $.extend() in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

The $.extend() method is defined as follows:

jQuery.extend([deep], target, object1, [objectN])

Extend an object with one or more other objects and return the extended object.
If no target is specified, the jQuery namespace itself is expanded. This helps plugin authors add new methods to jQuery. If the first parameter is set to true, jQuery returns a deep copy, recursively copying any objects found. Otherwise, the copy will share the structure with the original object. Undefined properties will not be copied, whereas properties inherited from the object's prototype will be copied.

Look at the code below to know how to use it, please see:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>extendFun</title>
<script src="../scripts/jquery-1.9.0.js" type="text/javascript"></script>
<meta name="author" content="Administrator" />
<!-- Date: 2013-01-30 -->
<script type="text/javascript">
$(function () {
var pageConfig= {};
var pageConfig=$.extend(pageConfig,{
createUrl: '${ROOT}/subject/createOrModifyPageTemplates',
deleteUrl: '${ROOT}/subject/deletePageTemplates',
modifyUrl: '${ROOT}/subject/createOrModifyPageTemplates',
infoName: 'pageTemplateInfo'
});
$("#subm").click(function(){
var posturl= pageConfig.deleteUrl;
alert(posturl);
});
})
</script>
</head>
<body>
<input id="subm" name="subm" type="button" value="clickme" >
</body>
</html>

Output result: ${ROOT}/subject/deletePageTemplates

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
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