Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Json extends jQuery

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how Json extends jQuery. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

If equal to then set to block, if not equal to this set to none, if the effect is set a little more complex, when clicking the button, not suddenly hide and show the submenu, but a highly smooth transition, then through the setTimeout to set the submenu of the height.

In the past, Json, which is used to extending Jquery, is very convenient to deal with json data in ajax development; in jQuery, it only provides a simple jQuery.getJSON () method, but does not provide jQuery's own conversion of json data, and it is easier to convert json strings into javascript data objects by using the eval () function, but it is more difficult to convert javascript data types into json strings.

Use prototype.js and jQuery when.

Extend the Json code for Jquery:

/ / expand jQuery's conversion of json strings to jQuery.extend ({/ * @ see converts json strings to objects * @ paramjson strings * @ return returns objects such as object,array,string * / evalJSON:function (strJson) {returneval ("(" + strJson+ ")");}}) JQuery.extend ({/ * @ see converts javascript data type to json string * @ param object to be converted. Support object,array,string,function,number,boolean,regexp*@return to return json string * / Json how to extend jQuery toJSON:function (object) {vartype=typeofobject; if ('object'==type) {if (Array==object.constructor) type='array'; elseif (RegExp==object.constructor) type='regexp'; elsetype='object' } switch (type) {case'undefined': case'unknown': return; break; case'function': case'boolean': case'regexp': returnobject.toString (); break; case'number': returnisFinite (object)? object.toString (): 'null'; break Case'string': return' "'+ object.replace (/ (\ |") / g, "\ $1"). Replace (/ n | r | tAccor gjigma function () {vara=arguments [0]; return (axiomatic accountingn')?'\ nthanks: (axiomatous accountingr')?'\ ringing: (axiomatic accountabilt`)?'\ tact: ""}) +''; break; case'object': if (object===null) return'null'; varresults= [] For (varpropertyinobject) {varvalue=jQuery.toJSON (property); if (valueworthy property undefined) results.push (jQuery.toJSON (property) +':'+ value);} return' {'+ results.join (',') +'}'; break; case'array': varresults= []; for (vari=0;i)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report