Javascript 使用函数时出现JS控制台错误
我知道这是一个简单的问题,但我找不到解决办法 调试控制台时出错,原因是.placeholder函数 我怎么修理它 链接到 HTMLJavascript 使用函数时出现JS控制台错误,javascript,jquery,Javascript,Jquery,我知道这是一个简单的问题,但我找不到解决办法 调试控制台时出错,原因是.placeholder函数 我怎么修理它 链接到 HTML 将jQuery放入代码中 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 正如我在评论中所说,您的代码中有两个错误 如果您在加载jQuery之前正在使用它,请更改顺序,首先加载jQuery 它是$('input
将jQuery放入代码中
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
正如我在评论中所说,您的代码中有两个错误
$('input,textarea')
而不是jQuery('input,textarea')
,基本上将代码更改为:
/* HTML5 placeholder jQuery plugin - v2.3.0
* Copyright (c)2015 Mathias Bynens
* 2015-11-13
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof module&&module.exports?require("jquery"):jQuery)}(function(a){function b(b){var c={},d=/^jQuery\d+$/;return a.each(b.attributes,function(a,b){b.specified&&!d.test(b.name)&&(c[b.name]=b.value)}),c}function c(b,c){var d=this,f=a(this);if(d.value===f.attr(h?"placeholder-x":"placeholder")&&f.hasClass(n.customClass))if(d.value="",f.removeClass(n.customClass),f.data("placeholder-password")){if(f=f.hide().nextAll('input[type="password"]:first').show().attr("id",f.removeAttr("id").data("placeholder-id")),b===!0)return f[0].value=c,c;f.focus()}else d==e()&&d.select()}function d(d){var e,f=this,g=a(this),i=f.id;if(!d||"blur"!==d.type||!g.hasClass(n.customClass))if(""===f.value){if("password"===f.type){if(!g.data("placeholder-textinput")){try{e=g.clone().prop({type:"text"})}catch(j){e=a("<input>").attr(a.extend(b(this),{type:"text"}))}e.removeAttr("name").data({"placeholder-enabled":!0,"placeholder-password":g,"placeholder-id":i}).bind("focus.placeholder",c),g.data({"placeholder-textinput":e,"placeholder-id":i}).before(e)}f.value="",g=g.removeAttr("id").hide().prevAll('input[type="text"]:first').attr("id",g.data("placeholder-id")).show()}else{var k=g.data("placeholder-password");k&&(k[0].value="",g.attr("id",g.data("placeholder-id")).show().nextAll('input[type="password"]:last').hide().removeAttr("id"))}g.addClass(n.customClass),g[0].value=g.attr(h?"placeholder-x":"placeholder")}else g.removeClass(n.customClass)}function e(){try{return document.activeElement}catch(a){}}var f,g,h=!1,i="[object OperaMini]"===Object.prototype.toString.call(window.operamini),j="placeholder"in document.createElement("input")&&!i&&!h,k="placeholder"in document.createElement("textarea")&&!i&&!h,l=a.valHooks,m=a.propHooks,n={};j&&k?(g=a.fn.placeholder=function(){return this},g.input=!0,g.textarea=!0):(g=a.fn.placeholder=function(b){var e={customClass:"placeholder"};return n=a.extend({},e,b),this.filter((j?"textarea":":input")+"["+(h?"placeholder-x":"placeholder")+"]").not("."+n.customClass).not(":radio, :checkbox, :hidden").bind({"focus.placeholder":c,"blur.placeholder":d}).data("placeholder-enabled",!0).trigger("blur.placeholder")},g.input=j,g.textarea=k,f={get:function(b){var c=a(b),d=c.data("placeholder-password");return d?d[0].value:c.data("placeholder-enabled")&&c.hasClass(n.customClass)?"":b.value},set:function(b,f){var g,h,i=a(b);return""!==f&&(g=i.data("placeholder-textinput"),h=i.data("placeholder-password"),g?(c.call(g[0],!0,f)||(b.value=f),g[0].value=f):h&&(c.call(b,!0,f)||(h[0].value=f),b.value=f)),i.data("placeholder-enabled")?(""===f?(b.value=f,b!=e()&&d.call(b)):(i.hasClass(n.customClass)&&c.call(b),b.value=f),i):(b.value=f,i)}},j||(l.input=f,m.value=f),k||(l.textarea=f,m.value=f),a(function(){a(document).delegate("form","submit.placeholder",function(){var b=a("."+n.customClass,this).each(function(){c.call(this,!0,"")});setTimeout(function(){b.each(d)},10)})}),a(window).bind("beforeunload.placeholder",function(){var b=!0;try{"javascript:void(0)"===document.activeElement.toString()&&(b=!1)}catch(c){}b&&a("."+n.customClass).each(function(){this.value=""})}))});
// Intializing placeholder
(function($) {
$('input, textarea').placeholder();
}(jQuery));
/*HTML5占位符jQuery插件-v2.3.0
*版权所有(c)2015 Mathias Bynens
* 2015-11-13
*/
!函数(a){“函数”==typeof define&&define.amd?define([“jquery”]],a):a(“对象”==typeof module&&module.exports?require(“jquery”):jquery)}(函数(a){函数b(b){var c={},d=/^jquery d+$/;返回a.each(b.attributes,函数(a,b){b.specified&&d.test?“占位符-x”:“占位符”)和&f.hasClass(n.customClass))如果(d.value=”“、f.removeClass(n.customClass)、f.data(“占位符密码”){if(f=f.hide().nextAll('input[type=“password”]:first').show().attr(“id”,f.removeAttr(“id”).data(“占位符id”)),b==!0)返回f[0]。value=c,c;f.focus()}否则d==e()&选择()函数d(d){var=e,f=a=this,g),i=f.id;if(!d | | |“blur”!==d.type | |!g.hasClass(n.customClass))if(“==f.value){if(“password”==f.type){if(!g.data(“占位符文本输入”){try{e=g.clone().prop type:“text”}catch(j){e=a(“).attr(a.extend(b)(this),{type:“text”)}extend”)}例如:removetr name(!placeholder(“占位符输入”)}.data”(“占位符”){placeholder”)}启用占位符”){focustomer”):i:{focustomer:“占位符”}:,c),g.data({“占位符文本输入”:e,“占位符id”:i}).before(e)f.value=“”,g=g.removeAttr(“id”).hide().prevAll('input[type=“text”]:first').attr(“id”,g.data(“占位符id”).show()}else({var k=g.data(“占位符密码”);k&(k[0].value=“”,g.attr(“id”,g.data(“占位符id”))).hide().show().nextAll('input[type=“last”):password(“id”)}g.addClass(n.customClass),g[0]。value=g.attr(h?“占位符-x”:“占位符”)}else g.removeClass(n.customClass)}函数e(){try{return document.activeElement}catch(a){}var f,g,h=!1,i=“[object OperaMini]==object.protostring.toString.call(window.OperaMini),j=“占位符”在document.createElement(“输入”)&!i&!h,k=“占位符”在document.createElement(“textarea”)&!i&&!h,l=a.valHooks,m=a.propHooks,n={};j&&k?(g=a.fn.placeholder=function(){返回this},g.input=!0,g.textarea=!0:(g=a.fn.placeholder=function(b){var e={customClass:“placeholder”};返回n=a.extend({},e,b),this.filter((j?“textarea”:):input“+”+(h?+)(“+x“+”)+customholder”)+n.not类).not(“:radio,:checkbox,:hidden”).bind({”focus.placeholder“:c,“blur.placeholder“:d}).data(“占位符启用”,!0).trigger(“blur.placeholder”)},g.input=j,g.textarea=k,f={get:function(b){var c=a(b),d=c.data(“占位符密码”);return d?d[0].value:c.data(“占位符启用”)&&c.hasglass(n.customClass”):b.value},set:function(b,f)(7)h=i.i.数据(占位者文本输入)、h=i.数据(占占位者密码(“占位者密码密码)、g?(c.c.c.c.c.c.c.g、h、h、h、h、h、h、h、h、h、h、h、h、h、h、h、h、h、h、h、h和f)f和(g.c.g.g、h.g、h、h、h、h、h、h、h、h.i.i.i.i.i.i.数据(“占位数据(“占占占位口令(“占占位密码密码密码密码密码密码)、g.g?(g?(g?(g.c.c.c.c.c.c.c.c.c.c.g[g[g[g[g[g[g[g[g[g[g[g[g[g[g[g[g[g[g[g[g[g[0[0[0[0},j||(l.input=f,m.value=f),k | |(l.textarea=f,m.value=f),a(function(){a(document).delegate(“form”,“submit.placeholder”,function(){var b=a(.“+n.customClass,this”)。each(function(){c.call(this,!0,”);setTimeout(function(){b.each(d)},10)}),a(window).bind(“beforeuload.placeholder”,function(){var b=!0;try{javascript:void(0)”===document.activeElement.toString()&&(b=!1)}catch(c){}b&&a(“.”+n.customClass).each(function(){this.value=”“})});
//初始化占位符
(函数($){
$('input,textarea')。占位符();
}(jQuery));
我拿了你的密码笔回购的叉子: 在进行以下更改后似乎可以正常工作:
希望能有所帮助!请添加更多详细信息,前提是您的代码有用。告诉我们您尝试了什么。抱歉,正在编辑问题。我有一个代码笔链接,请查看。jquery未定义,无法修复。太棒了!很高兴提供帮助。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
/* HTML5 placeholder jQuery plugin - v2.3.0
* Copyright (c)2015 Mathias Bynens
* 2015-11-13
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof module&&module.exports?require("jquery"):jQuery)}(function(a){function b(b){var c={},d=/^jQuery\d+$/;return a.each(b.attributes,function(a,b){b.specified&&!d.test(b.name)&&(c[b.name]=b.value)}),c}function c(b,c){var d=this,f=a(this);if(d.value===f.attr(h?"placeholder-x":"placeholder")&&f.hasClass(n.customClass))if(d.value="",f.removeClass(n.customClass),f.data("placeholder-password")){if(f=f.hide().nextAll('input[type="password"]:first').show().attr("id",f.removeAttr("id").data("placeholder-id")),b===!0)return f[0].value=c,c;f.focus()}else d==e()&&d.select()}function d(d){var e,f=this,g=a(this),i=f.id;if(!d||"blur"!==d.type||!g.hasClass(n.customClass))if(""===f.value){if("password"===f.type){if(!g.data("placeholder-textinput")){try{e=g.clone().prop({type:"text"})}catch(j){e=a("<input>").attr(a.extend(b(this),{type:"text"}))}e.removeAttr("name").data({"placeholder-enabled":!0,"placeholder-password":g,"placeholder-id":i}).bind("focus.placeholder",c),g.data({"placeholder-textinput":e,"placeholder-id":i}).before(e)}f.value="",g=g.removeAttr("id").hide().prevAll('input[type="text"]:first').attr("id",g.data("placeholder-id")).show()}else{var k=g.data("placeholder-password");k&&(k[0].value="",g.attr("id",g.data("placeholder-id")).show().nextAll('input[type="password"]:last').hide().removeAttr("id"))}g.addClass(n.customClass),g[0].value=g.attr(h?"placeholder-x":"placeholder")}else g.removeClass(n.customClass)}function e(){try{return document.activeElement}catch(a){}}var f,g,h=!1,i="[object OperaMini]"===Object.prototype.toString.call(window.operamini),j="placeholder"in document.createElement("input")&&!i&&!h,k="placeholder"in document.createElement("textarea")&&!i&&!h,l=a.valHooks,m=a.propHooks,n={};j&&k?(g=a.fn.placeholder=function(){return this},g.input=!0,g.textarea=!0):(g=a.fn.placeholder=function(b){var e={customClass:"placeholder"};return n=a.extend({},e,b),this.filter((j?"textarea":":input")+"["+(h?"placeholder-x":"placeholder")+"]").not("."+n.customClass).not(":radio, :checkbox, :hidden").bind({"focus.placeholder":c,"blur.placeholder":d}).data("placeholder-enabled",!0).trigger("blur.placeholder")},g.input=j,g.textarea=k,f={get:function(b){var c=a(b),d=c.data("placeholder-password");return d?d[0].value:c.data("placeholder-enabled")&&c.hasClass(n.customClass)?"":b.value},set:function(b,f){var g,h,i=a(b);return""!==f&&(g=i.data("placeholder-textinput"),h=i.data("placeholder-password"),g?(c.call(g[0],!0,f)||(b.value=f),g[0].value=f):h&&(c.call(b,!0,f)||(h[0].value=f),b.value=f)),i.data("placeholder-enabled")?(""===f?(b.value=f,b!=e()&&d.call(b)):(i.hasClass(n.customClass)&&c.call(b),b.value=f),i):(b.value=f,i)}},j||(l.input=f,m.value=f),k||(l.textarea=f,m.value=f),a(function(){a(document).delegate("form","submit.placeholder",function(){var b=a("."+n.customClass,this).each(function(){c.call(this,!0,"")});setTimeout(function(){b.each(d)},10)})}),a(window).bind("beforeunload.placeholder",function(){var b=!0;try{"javascript:void(0)"===document.activeElement.toString()&&(b=!1)}catch(c){}b&&a("."+n.customClass).each(function(){this.value=""})}))});
// Intializing placeholder
(function($) {
$('input, textarea').placeholder();
}(jQuery));
jQuery('input, textarea').placeholder();
(function($) {
$(document).ready(function(){
jQuery('input, textarea').placeholder();
});
}(jQuery));