Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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从字符串中标记其内容_Javascript_Jquery_Regex - Fatal编程技术网

删除“;表格「;使用javascript从字符串中标记其内容

删除“;表格「;使用javascript从字符串中标记其内容,javascript,jquery,regex,Javascript,Jquery,Regex,我需要从ajax响应内容中删除表单标记。我试过下面的代码,但它不工作。任何帮助都将不胜感激 new Ajax.Request( url, { method: "post", onSuccess: function (b) { var a = $("test"); a.update(b.responseText.replace("[<](/)?form[^>]*[>]", "")); } }); newajax.Request(

我需要从ajax响应内容中删除表单标记。我试过下面的代码,但它不工作。任何帮助都将不胜感激

new Ajax.Request(
  url, {
    method: "post",
    onSuccess: function (b) {
      var a = $("test");

      a.update(b.responseText.replace("[<](/)?form[^>]*[>]", ""));
  }
});
newajax.Request(
网址{
方法:“张贴”,
onSuccess:函数(b){
var a=$(“测试”);
a、 更新(b.responseText.replace(“[]*[>]”,“”);
}
});
使用javascript从字符串中删除“Form”标记及其内容

假设您的意思是从字符串中删除“Form”标记及其内容

如果您使用的是jquery,则可以尝试

var $bResponseText = $( b.responseText );
$bResponseText.find( "form" ).remove();
b.responseText = $bResponseText[0].outerHTML;
在使用
update
功能之前

或者使用jquery的另一种方法

$("test").append( b.responseText );
$("test").find( "form" ).last().remove();
使用javascript从字符串中删除“Form”标记及其内容

假设您的意思是从字符串中删除“Form”标记及其内容

如果您使用的是jquery,则可以尝试

var $bResponseText = $( b.responseText );
$bResponseText.find( "form" ).remove();
b.responseText = $bResponseText[0].outerHTML;
在使用
update
功能之前

或者使用jquery的另一种方法

$("test").append( b.responseText );
$("test").find( "form" ).last().remove();
(在这个答案中不使用jQuery,因为问题中的代码显然使用了jQuery。)

最简单的方法是解析HTML(浏览器很乐意为您这样做),删除结果中的
表单
元素,然后将其序列化回字符串(如果需要,浏览器也很乐意为您这样做)

例如(不使用jQuery):

(在这个答案中不使用jQuery,因为问题中的代码显然使用了jQuery。)

最简单的方法是解析HTML(浏览器很乐意为您这样做),删除结果中的
表单
元素,然后将其序列化回字符串(如果需要,浏览器也很乐意为您这样做)

例如(不使用jQuery):


您可以用

//检测表单时,可以使用id或类选择器
var formContent=$('form');
//将表单替换为其内容,以便删除表单标记
替换为(formContent.html())

表内内容

您可以简单地将表单内容替换为

//检测表单时,可以使用id或类选择器
var formContent=$('form');
//将表单替换为其内容,以便删除表单标记
替换为(formContent.html())

表内内容

您可以使用以下内容:-

  • 创建临时div:-
    var tempDiv=document.createElement(“div”)
  • 然后将响应分配为其innerHTML:-
    tempDiv.innerHTML=b.responseText
  • 之后,用户querySelectorAll从temp div上面获取所有表单元素:-
    var allForms=tempDiv.querySelectorAll(“表单”)
  • 然后迭代allForms和user remove()方法以逐个删除表单
  • 然后使用tempDiv的innerHTML获取不带表单元素的字符串:-
    a.update(tempDiv.innerHTML)

  • 您可以使用以下内容:-

  • 创建临时div:-
    var tempDiv=document.createElement(“div”)
  • 然后将响应分配为其innerHTML:-
    tempDiv.innerHTML=b.responseText
  • 之后,用户querySelectorAll从temp div上面获取所有表单元素:-
    var allForms=tempDiv.querySelectorAll(“表单”)
  • 然后迭代allForms和user remove()方法以逐个删除表单
  • 然后使用tempDiv的innerHTML获取不带表单元素的字符串:-
    a.update(tempDiv.innerHTML)

  • 在我看来,这不像jQuery。看起来像。您可以使用
    共享一个工作片段吗?不确定jquery一开始是否有
    update
    。@gurvinder372:
    update
    也是PrototypeJS的东西,就像
    Ajax。请求
    。向OP发送请求-您是否使用jquery?请澄清。我觉得这不像jQuery。看起来像。您可以使用
    共享一个工作片段吗?不确定jquery一开始是否有
    update
    。@gurvinder372:
    update
    也是PrototypeJS的东西,就像
    Ajax。请求
    。向OP发送请求-您是否使用jquery?请澄清。