1 $.widget ()
Must reference
<script src="@Url. Content ("~/scripts/jquery-ui-latest.js?v="+ viewbag.vv+"1")" type="text/javascript "></script>
2.
(function ($) {$.widget ("HW. Camscan", {options: {//plug -In Parameters }, ///Create the widget to display the corresponding UI according to the configuration_create:function () {varSelf = This; //here to initialize the information}, _hasnocontrol:function (idprefix) {//internal methods defined in the plug- in}, Scanupload:function (Value, fileName) {//external methods defined in the plug- in}, Destroy:function () { This. Element.empty (); $. Widget.prototype.destroy.apply ( This, arguments); } });}) (jQuery);
3 How to use
$("#sa"). Camscan ({scanurl:"http://localhost:56630/", Scanaction:"Testplub/scanupload", UserID:"99999", Camurl:"http://localhost:56630/", Camaction:"Testplub/camupload" });
4 How to invoke a method in a plug-in
$ ("#sa"). Camscan ("scanupload" "params " " FileName")
where params filename corresponds to value and filename in the above scanupload
5 How to get to events in plugins
Using Trigger in plugins
JQuery ("#" + ID). Trigger ('scanuploadscuess'). JPG Upload Successful! "); // successfully triggering an event
Use bind when page loads
$ ("#sa"). Bind ("camsmsuccess", function (E, Value) {alert (value);});
6 trigger multiple parameters (independent of plug-ins)
JQuery ("#" + ID). Trigger ('jsimg', [image, Saomiaoid]); // successfully triggering an event
Calling methods
$ ("# @ViewBag. Tabcid""_scancontrol"). Bind ( "jsimg", Function (e, img,id) {where the IMG ID is the outgoing parameter}
With the jquery trigger and bind methods we can get the events defined in the plugin
Plug-in development in the jquery UI