当前位置:   article > 正文

实时监听input值的改变_jqmigrate: logging is active

jqmigrate: logging is active
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>input value</title>
  6. <script type="text/javascript" src="jquery.2.js"></script>
  7. <script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
  8. </head>
  9. <body>
  10. <table>
  11. <tr>
  12. <td>此处值通过js设置:</td>
  13. <td><input id="jsUserName" type="text" name="jsUserName" disabled="disabled" /></td>
  14. </tr>
  15. <tr>
  16. <td>此处输入值:</td>
  17. <td><input id="userName" type="text" name="userName"/></td>
  18. </tr>
  19. </table>
  20. <script type="text/javascript">
  21. $(function()
  22. {
  23. var jsUserName = "";
  24. if($.browser.msie) // IE浏览器
  25. {
  26. $("#userName").get(0).onpropertychange = setJsUserName;
  27. $("#jsUserName").get(0).onpropertychange = handle;
  28. }
  29. else // 其他浏览器
  30. {
  31. var intervalName; //定时器句柄
  32. $("#userName").get(0).addEventListener("input",setJsUserName,false);
  33. // 获得焦点时,启动定时器
  34. $("#userName").focus(function(){
  35. intervalName = setInterval(handle,1000);
  36. });
  37. // 失去焦点时,清除定时器
  38. $("#userName").blur(function()
  39. {
  40. clearInterval(intervalName);
  41. });
  42. }
  43. // 设置jsUserName input的值
  44. function setJsUserName()
  45. {
  46. $("#jsUserName").val($(this).val());
  47. }
  48. // jsUserName input的值改变时执行的函数
  49. function handle()
  50. {
  51. // IE浏览器此处判断没什么意义,但为了统一,且提取公共代码而这样处理。
  52. if($("#jsUserName").val() != jsUserName)
  53. {
  54. $("#toolTip").remove();
  55. $("#jsUserName").parent().append("<span id='toolTip'>看到这里的信息表明,通过js改变input的值也能响应相应事件:<span style='color:red;'>" + $("#jsUserName").val() + "</span></span>");
  56. jsUserName = $("#jsUserName").val();
  57. }
  58. }
  59. });
  60. </script>
  61. </body>
  62. </html>


/***************************此处需要引入jquery-migrate.js来兼容jquery1.9之后的版本,已经下载如下:*******************************/
  1. /*!
  2. * jQuery Migrate - v1.2.1 - 2013-05-08
  3. * https://github.com/jquery/jquery-migrate
  4. * Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors; Licensed MIT
  5. */
  6. (function( jQuery, window, undefined ) {
  7. // See http://bugs.jquery.com/ticket/13335
  8. // "use strict";
  9. var warnedAbout = {};
  10. // List of warnings already given; public read only
  11. jQuery.migrateWarnings = [];
  12. // Set to true to prevent console output; migrateWarnings still maintained
  13. // jQuery.migrateMute = false;
  14. // Show a message on the console so devs know we're active
  15. if ( !jQuery.migrateMute && window.console && window.console.log ) {
  16. window.console.log("JQMIGRATE: Logging is active");
  17. }
  18. // Set to false to disable traces that appear with warnings
  19. if ( jQuery.migrateTrace === undefined ) {
  20. jQuery.migrateTrace = true;
  21. }
  22. // Forget any warnings we've already given; public
  23. jQuery.migrateReset = function() {
  24. warnedAbout = {};
  25. jQuery.migrateWarnings.length = 0;
  26. };
  27. function migrateWarn( msg) {
  28. var console = window.console;
  29. if ( !warnedAbout[ msg ] ) {
  30. warnedAbout[ msg ] = true;
  31. jQuery.migrateWarnings.push( msg );
  32. if ( console && console.warn && !jQuery.migrateMute ) {
  33. console.warn( "JQMIGRATE: " + msg );
  34. if ( jQuery.migrateTrace && console.trace ) {
  35. console.trace();
  36. }
  37. }
  38. }
  39. }
  40. function migrateWarnProp( obj, prop, value, msg ) {
  41. if ( Object.defineProperty ) {
  42. // On ES5 browsers (non-oldIE), warn if the code tries to get prop;
  43. // allow property to be overwritten in case some other plugin wants it
  44. try {
  45. Object.defineProperty( obj, prop, {
  46. configurable: true,
  47. enumerable: true,
  48. get: function() {
  49. migrateWarn( msg );
  50. return value;
  51. },
  52. set: function( newValue ) {
  53. migrateWarn( msg );
  54. value = newValue;
  55. }
  56. });
  57. return;
  58. } catch( err ) {
  59. // IE8 is a dope about Object.defineProperty, can't warn there
  60. }
  61. }
  62. // Non-ES5 (or broken) browser; just set the property
  63. jQuery._definePropertyBroken = true;
  64. obj[ prop ] = value;
  65. }
  66. if ( document.compatMode === "BackCompat" ) {
  67. // jQuery has never supported or tested Quirks Mode
  68. migrateWarn( "jQuery is not compatible with Quirks Mode" );
  69. }
  70. var attrFn = jQuery( "<input/>", { size: 1 } ).attr("size") && jQuery.attrFn,
  71. oldAttr = jQuery.attr,
  72. valueAttrGet = jQuery.attrHooks.value && jQuery.attrHooks.value.get ||
  73. function() { return null; },
  74. valueAttrSet = jQuery.attrHooks.value && jQuery.attrHooks.value.set ||
  75. function() { return undefined; },
  76. rnoType = /^(?:input|button)$/i,
  77. rnoAttrNodeType = /^[238]$/,
  78. rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
  79. ruseDefault = /^(?:checked|selected)$/i;
  80. // jQuery.attrFn
  81. migrateWarnProp( jQuery, "attrFn", attrFn || {}, "jQuery.attrFn is deprecated" );
  82. jQuery.attr = function( elem, name, value, pass ) {
  83. var lowerName = name.toLowerCase(),
  84. nType = elem && elem.nodeType;
  85. if ( pass ) {
  86. // Since pass is used internally, we only warn for new jQuery
  87. // versions where there isn't a pass arg in the formal params
  88. if ( oldAttr.length < 4 ) {
  89. migrateWarn("jQuery.fn.attr( props, pass ) is deprecated");
  90. }
  91. if ( elem && !rnoAttrNodeType.test( nType ) &&
  92. (attrFn ? name in attrFn : jQuery.isFunction(jQuery.fn[name])) ) {
  93. return jQuery( elem )[ name ]( value );
  94. }
  95. }
  96. // Warn if user tries to set `type`, since it breaks on IE 6/7/8; by checking
  97. // for disconnected elements we don't warn on $( "<button>", { type: "button" } ).
  98. if ( name === "type" && value !== undefined && rnoType.test( elem.nodeName ) && elem.parentNode ) {
  99. migrateWarn("Can't change the 'type' of an input or button in IE 6/7/8");
  100. }
  101. // Restore boolHook for boolean property/attribute synchronization
  102. if ( !jQuery.attrHooks[ lowerName ] && rboolean.test( lowerName ) ) {
  103. jQuery.attrHooks[ lowerName ] = {
  104. get: function( elem, name ) {
  105. // Align boolean attributes with corresponding properties
  106. // Fall back to attribute presence where some booleans are not supported
  107. var attrNode,
  108. property = jQuery.prop( elem, name );
  109. return property === true || typeof property !== "boolean" &&
  110. ( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ?
  111. name.toLowerCase() :
  112. undefined;
  113. },
  114. set: function( elem, value, name ) {
  115. var propName;
  116. if ( value === false ) {
  117. // Remove boolean attributes when set to false
  118. jQuery.removeAttr( elem, name );
  119. } else {
  120. // value is true since we know at this point it's type boolean and not false
  121. // Set boolean attributes to the same name and set the DOM property
  122. propName = jQuery.propFix[ name ] || name;
  123. if ( propName in elem ) {
  124. // Only set the IDL specifically if it already exists on the element
  125. elem[ propName ] = true;
  126. }
  127. elem.setAttribute( name, name.toLowerCase() );
  128. }
  129. return name;
  130. }
  131. };
  132. // Warn only for attributes that can remain distinct from their properties post-1.9
  133. if ( ruseDefault.test( lowerName ) ) {
  134. migrateWarn( "jQuery.fn.attr('" + lowerName + "') may use property instead of attribute" );
  135. }
  136. }
  137. return oldAttr.call( jQuery, elem, name, value );
  138. };
  139. // attrHooks: value
  140. jQuery.attrHooks.value = {
  141. get: function( elem, name ) {
  142. var nodeName = ( elem.nodeName || "" ).toLowerCase();
  143. if ( nodeName === "button" ) {
  144. return valueAttrGet.apply( this, arguments );
  145. }
  146. if ( nodeName !== "input" && nodeName !== "option" ) {
  147. migrateWarn("jQuery.fn.attr('value') no longer gets properties");
  148. }
  149. return name in elem ?
  150. elem.value :
  151. null;
  152. },
  153. set: function( elem, value ) {
  154. var nodeName = ( elem.nodeName || "" ).toLowerCase();
  155. if ( nodeName === "button" ) {
  156. return valueAttrSet.apply( this, arguments );
  157. }
  158. if ( nodeName !== "input" && nodeName !== "option" ) {
  159. migrateWarn("jQuery.fn.attr('value', val) no longer sets properties");
  160. }
  161. // Does not return so that setAttribute is also used
  162. elem.value = value;
  163. }
  164. };
  165. var matched, browser,
  166. oldInit = jQuery.fn.init,
  167. oldParseJSON = jQuery.parseJSON,
  168. // Note: XSS check is done below after string is trimmed
  169. rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/;
  170. // $(html) "looks like html" rule change
  171. jQuery.fn.init = function( selector, context, rootjQuery ) {
  172. var match;
  173. if ( selector && typeof selector === "string" && !jQuery.isPlainObject( context ) &&
  174. (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) {
  175. // This is an HTML string according to the "old" rules; is it still?
  176. if ( selector.charAt( 0 ) !== "<" ) {
  177. migrateWarn("$(html) HTML strings must start with '<' character");
  178. }
  179. if ( match[ 3 ] ) {
  180. migrateWarn("$(html) HTML text after last tag is ignored");
  181. }
  182. // Consistently reject any HTML-like string starting with a hash (#9521)
  183. // Note that this may break jQuery 1.6.x code that otherwise would work.
  184. if ( match[ 0 ].charAt( 0 ) === "#" ) {
  185. migrateWarn("HTML string cannot start with a '#' character");
  186. jQuery.error("JQMIGRATE: Invalid selector string (XSS)");
  187. }
  188. // Now process using loose rules; let pre-1.8 play too
  189. if ( context && context.context ) {
  190. // jQuery object as context; parseHTML expects a DOM object
  191. context = context.context;
  192. }
  193. if ( jQuery.parseHTML ) {
  194. return oldInit.call( this, jQuery.parseHTML( match[ 2 ], context, true ),
  195. context, rootjQuery );
  196. }
  197. }
  198. return oldInit.apply( this, arguments );
  199. };
  200. jQuery.fn.init.prototype = jQuery.fn;
  201. // Let $.parseJSON(falsy_value) return null
  202. jQuery.parseJSON = function( json ) {
  203. if ( !json && json !== null ) {
  204. migrateWarn("jQuery.parseJSON requires a valid JSON string");
  205. return null;
  206. }
  207. return oldParseJSON.apply( this, arguments );
  208. };
  209. jQuery.uaMatch = function( ua ) {
  210. ua = ua.toLowerCase();
  211. var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
  212. /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
  213. /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
  214. /(msie) ([\w.]+)/.exec( ua ) ||
  215. ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
  216. [];
  217. return {
  218. browser: match[ 1 ] || "",
  219. version: match[ 2 ] || "0"
  220. };
  221. };
  222. // Don't clobber any existing jQuery.browser in case it's different
  223. if ( !jQuery.browser ) {
  224. matched = jQuery.uaMatch( navigator.userAgent );
  225. browser = {};
  226. if ( matched.browser ) {
  227. browser[ matched.browser ] = true;
  228. browser.version = matched.version;
  229. }
  230. // Chrome is Webkit, but Webkit is also Safari.
  231. if ( browser.chrome ) {
  232. browser.webkit = true;
  233. } else if ( browser.webkit ) {
  234. browser.safari = true;
  235. }
  236. jQuery.browser = browser;
  237. }
  238. // Warn if the code tries to get jQuery.browser
  239. migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" );
  240. jQuery.sub = function() {
  241. function jQuerySub( selector, context ) {
  242. return new jQuerySub.fn.init( selector, context );
  243. }
  244. jQuery.extend( true, jQuerySub, this );
  245. jQuerySub.superclass = this;
  246. jQuerySub.fn = jQuerySub.prototype = this();
  247. jQuerySub.fn.constructor = jQuerySub;
  248. jQuerySub.sub = this.sub;
  249. jQuerySub.fn.init = function init( selector, context ) {
  250. if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
  251. context = jQuerySub( context );
  252. }
  253. return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
  254. };
  255. jQuerySub.fn.init.prototype = jQuerySub.fn;
  256. var rootjQuerySub = jQuerySub(document);
  257. migrateWarn( "jQuery.sub() is deprecated" );
  258. return jQuerySub;
  259. };
  260. // Ensure that $.ajax gets the new parseJSON defined in core.js
  261. jQuery.ajaxSetup({
  262. converters: {
  263. "text json": jQuery.parseJSON
  264. }
  265. });
  266. var oldFnData = jQuery.fn.data;
  267. jQuery.fn.data = function( name ) {
  268. var ret, evt,
  269. elem = this[0];
  270. // Handles 1.7 which has this behavior and 1.8 which doesn't
  271. if ( elem && name === "events" && arguments.length === 1 ) {
  272. ret = jQuery.data( elem, name );
  273. evt = jQuery._data( elem, name );
  274. if ( ( ret === undefined || ret === evt ) && evt !== undefined ) {
  275. migrateWarn("Use of jQuery.fn.data('events') is deprecated");
  276. return evt;
  277. }
  278. }
  279. return oldFnData.apply( this, arguments );
  280. };
  281. var rscriptType = /\/(java|ecma)script/i,
  282. oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
  283. jQuery.fn.andSelf = function() {
  284. migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()");
  285. return oldSelf.apply( this, arguments );
  286. };
  287. // Since jQuery.clean is used internally on older versions, we only shim if it's missing
  288. if ( !jQuery.clean ) {
  289. jQuery.clean = function( elems, context, fragment, scripts ) {
  290. // Set context per 1.8 logic
  291. context = context || document;
  292. context = !context.nodeType && context[0] || context;
  293. context = context.ownerDocument || context;
  294. migrateWarn("jQuery.clean() is deprecated");
  295. var i, elem, handleScript, jsTags,
  296. ret = [];
  297. jQuery.merge( ret, jQuery.buildFragment( elems, context ).childNodes );
  298. // Complex logic lifted directly from jQuery 1.8
  299. if ( fragment ) {
  300. // Special handling of each script element
  301. handleScript = function( elem ) {
  302. // Check if we consider it executable
  303. if ( !elem.type || rscriptType.test( elem.type ) ) {
  304. // Detach the script and store it in the scripts array (if provided) or the fragment
  305. // Return truthy to indicate that it has been handled
  306. return scripts ?
  307. scripts.push( elem.parentNode ? elem.parentNode.removeChild( elem ) : elem ) :
  308. fragment.appendChild( elem );
  309. }
  310. };
  311. for ( i = 0; (elem = ret[i]) != null; i++ ) {
  312. // Check if we're done after handling an executable script
  313. if ( !( jQuery.nodeName( elem, "script" ) && handleScript( elem ) ) ) {
  314. // Append to fragment and handle embedded scripts
  315. fragment.appendChild( elem );
  316. if ( typeof elem.getElementsByTagName !== "undefined" ) {
  317. // handleScript alters the DOM, so use jQuery.merge to ensure snapshot iteration
  318. jsTags = jQuery.grep( jQuery.merge( [], elem.getElementsByTagName("script") ), handleScript );
  319. // Splice the scripts into ret after their former ancestor and advance our index beyond them
  320. ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
  321. i += jsTags.length;
  322. }
  323. }
  324. }
  325. }
  326. return ret;
  327. };
  328. }
  329. var eventAdd = jQuery.event.add,
  330. eventRemove = jQuery.event.remove,
  331. eventTrigger = jQuery.event.trigger,
  332. oldToggle = jQuery.fn.toggle,
  333. oldLive = jQuery.fn.live,
  334. oldDie = jQuery.fn.die,
  335. ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess",
  336. rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ),
  337. rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
  338. hoverHack = function( events ) {
  339. if ( typeof( events ) !== "string" || jQuery.event.special.hover ) {
  340. return events;
  341. }
  342. if ( rhoverHack.test( events ) ) {
  343. migrateWarn("'hover' pseudo-event is deprecated, use 'mouseenter mouseleave'");
  344. }
  345. return events && events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
  346. };
  347. // Event props removed in 1.9, put them back if needed; no practical way to warn them
  348. if ( jQuery.event.props && jQuery.event.props[ 0 ] !== "attrChange" ) {
  349. jQuery.event.props.unshift( "attrChange", "attrName", "relatedNode", "srcElement" );
  350. }
  351. // Undocumented jQuery.event.handle was "deprecated" in jQuery 1.7
  352. if ( jQuery.event.dispatch ) {
  353. migrateWarnProp( jQuery.event, "handle", jQuery.event.dispatch, "jQuery.event.handle is undocumented and deprecated" );
  354. }
  355. // Support for 'hover' pseudo-event and ajax event warnings
  356. jQuery.event.add = function( elem, types, handler, data, selector ){
  357. if ( elem !== document && rajaxEvent.test( types ) ) {
  358. migrateWarn( "AJAX events should be attached to document: " + types );
  359. }
  360. eventAdd.call( this, elem, hoverHack( types || "" ), handler, data, selector );
  361. };
  362. jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){
  363. eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes );
  364. };
  365. jQuery.fn.error = function() {
  366. var args = Array.prototype.slice.call( arguments, 0);
  367. migrateWarn("jQuery.fn.error() is deprecated");
  368. args.splice( 0, 0, "error" );
  369. if ( arguments.length ) {
  370. return this.bind.apply( this, args );
  371. }
  372. // error event should not bubble to window, although it does pre-1.7
  373. this.triggerHandler.apply( this, args );
  374. return this;
  375. };
  376. jQuery.fn.toggle = function( fn, fn2 ) {
  377. // Don't mess with animation or css toggles
  378. if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) {
  379. return oldToggle.apply( this, arguments );
  380. }
  381. migrateWarn("jQuery.fn.toggle(handler, handler...) is deprecated");
  382. // Save reference to arguments for access in closure
  383. var args = arguments,
  384. guid = fn.guid || jQuery.guid++,
  385. i = 0,
  386. toggler = function( event ) {
  387. // Figure out which function to execute
  388. var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
  389. jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
  390. // Make sure that clicks stop
  391. event.preventDefault();
  392. // and execute the function
  393. return args[ lastToggle ].apply( this, arguments ) || false;
  394. };
  395. // link all the functions, so any of them can unbind this click handler
  396. toggler.guid = guid;
  397. while ( i < args.length ) {
  398. args[ i++ ].guid = guid;
  399. }
  400. return this.click( toggler );
  401. };
  402. jQuery.fn.live = function( types, data, fn ) {
  403. migrateWarn("jQuery.fn.live() is deprecated");
  404. if ( oldLive ) {
  405. return oldLive.apply( this, arguments );
  406. }
  407. jQuery( this.context ).on( types, this.selector, data, fn );
  408. return this;
  409. };
  410. jQuery.fn.die = function( types, fn ) {
  411. migrateWarn("jQuery.fn.die() is deprecated");
  412. if ( oldDie ) {
  413. return oldDie.apply( this, arguments );
  414. }
  415. jQuery( this.context ).off( types, this.selector || "**", fn );
  416. return this;
  417. };
  418. // Turn global events into document-triggered events
  419. jQuery.event.trigger = function( event, data, elem, onlyHandlers ){
  420. if ( !elem && !rajaxEvent.test( event ) ) {
  421. migrateWarn( "Global events are undocumented and deprecated" );
  422. }
  423. return eventTrigger.call( this, event, data, elem || document, onlyHandlers );
  424. };
  425. jQuery.each( ajaxEvents.split("|"),
  426. function( _, name ) {
  427. jQuery.event.special[ name ] = {
  428. setup: function() {
  429. var elem = this;
  430. // The document needs no shimming; must be !== for oldIE
  431. if ( elem !== document ) {
  432. jQuery.event.add( document, name + "." + jQuery.guid, function() {
  433. jQuery.event.trigger( name, null, elem, true );
  434. });
  435. jQuery._data( this, name, jQuery.guid++ );
  436. }
  437. return false;
  438. },
  439. teardown: function() {
  440. if ( this !== document ) {
  441. jQuery.event.remove( document, name + "." + jQuery._data( this, name ) );
  442. }
  443. return false;
  444. }
  445. };
  446. }
  447. );
  448. })( jQuery, window );




声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/315707
推荐阅读
相关标签
  

闽ICP备14008679号