Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery before()输出为字符串而不是HTML_Javascript_Jquery_Wordpress_Gravity Forms Plugin - Fatal编程技术网

Javascript jQuery before()输出为字符串而不是HTML

Javascript jQuery before()输出为字符串而不是HTML,javascript,jquery,wordpress,gravity-forms-plugin,Javascript,Jquery,Wordpress,Gravity Forms Plugin,我试图在重力表单输入之前使用一些简单的jQuery注入一些HTML 这是我的密码: var formInputs = jQuery( "form li input" ) formInputs.each(function( index ) { this.before('<h1>Hello, world!</h1>'); }); 下面是它在每个输入上的外观 是否存在与重力形式的某种形式的冲突 编辑:我试着替换 this.before('<h1>Hello,

我试图在重力表单输入之前使用一些简单的jQuery注入一些HTML

这是我的密码:

var formInputs = jQuery( "form li input" )

formInputs.each(function( index ) {
  this.before('<h1>Hello, world!</h1>');
});
下面是它在每个输入上的外观

是否存在与重力形式的某种形式的冲突

编辑:我试着替换

this.before('<h1>Hello, world!</h1>');

在jQuery“你好,世界!”之前

取而代之的是jQuery对象

你试过这个吗

jQuery('<h1>Hello World!</h1>').insertBefore(this);
你试过这个吗

jQuery('<h1>Hello World!</h1>').insertBefore(this);
每个方法引用的是JavaScript对象,而不是该元素的jQuery对象,因此如果要在该元素上使用任何jQuery方法,必须使用jQuery对其进行包装

var formInputs = jQuery( "form li input" )

formInputs.each(function( index ) {
  jQuery(this).before( document.createTextNode('<h1>Hello, world!</h1>') );
});
每个方法引用的是JavaScript对象,而不是该元素的jQuery对象,因此如果要在该元素上使用任何jQuery方法,必须使用jQuery对其进行包装

var formInputs = jQuery( "form li input" )

formInputs.each(function( index ) {
  jQuery(this).before( document.createTextNode('<h1>Hello, world!</h1>') );
});

试试这个。在jQuery“你好,世界!”之前@卡梅隆赫德:谢谢你的建议,请看编辑尝试一下。在jquery‘你好,世界!’之前@卡梅隆赫德:谢谢你的建议,请看编辑一开始就把链接搞砸了。已修复。他想转义HTML并将其作为纯文本而不是HTML输出。@KhorshedAlam nono Sean做对了。正在尝试注入HTML。这就是JSFIDLE所做的。它正在创建一个html格式的H1。@Sean很好奇,你知道为什么.insertBefore有效,而.before无效吗?一开始就把链接搞砸了。已修复。他想转义HTML并将其作为纯文本而不是HTML输出。@KhorshedAlam nono Sean做对了。正在尝试注入HTML。这就是JSFIDLE所做的。它正在创建一个html格式的H1。@Sean很好奇,你知道为什么.insertBefore有效而.before无效吗?