Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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中更改标记名?_Javascript_Jquery_Html - Fatal编程技术网

如何在javascript或jquery中更改标记名?

如何在javascript或jquery中更改标记名?,javascript,jquery,html,Javascript,Jquery,Html,我有ajax表格。当用户提交表单时,javascript必须等待响应。所以我想把按钮改成p标签。有人知道如何在javascript或jquery中更改标记名吗 <form action="addcomment.php" class="ajaxform" > <input type="text" placeholder="Comment" id="comment" > <button>Add Comment</button> &

我有ajax表格。当用户提交表单时,javascript必须等待响应。所以我想把
按钮
改成
p
标签。有人知道如何在javascript或jquery中更改标记名吗

<form action="addcomment.php"  class="ajaxform" >
     <input type="text" placeholder="Comment" id="comment" >
     <button>Add Comment</button>
</form>

添加注释

而不是“更改”标签,您应该考虑所有要创建的标签,然后更改它们的可见性。

HTML:


添加注释
正在加载

JS:

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
//隐藏和显示
$(“按钮”).hide();
$(“p”).show();
});
});

而不是“更改”标签,您应该考虑所有要创建的标签,然后更改它们的可见性。

HTML:


添加注释
正在加载

JS:

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
//隐藏和显示
$(“按钮”).hide();
$(“p”).show();
});
});

将文本段落附加到按钮的父级,然后删除按钮本身

$("button").click(function() {
  $(this).parent().append($("<p>Loading Text</p>"));
  $(this).remove();
  $.ajax({ ... });
});
$(“按钮”)。单击(函数(){
$(this.parent().append($(“加载文本”

”); $(this.remove(); $.ajax({…}); });
将文本段落附加到按钮的父级,然后删除按钮本身

$("button").click(function() {
  $(this).parent().append($("<p>Loading Text</p>"));
  $(this).remove();
  $.ajax({ ... });
});
$(“按钮”)。单击(函数(){
$(this.parent().append($(“加载文本”

”); $(this.remove(); $.ajax({…}); });
只需禁用按钮,即可防止在ajax过程中多次单击:

$( "button" ).click(function() {
  var obj = $(this);
  obj.attr("disabled","disabled");
  $.ajax({ 
         ... 
       success: function() {
         obj.removeAttr("disabled");
       }
  });
});

只需禁用按钮,即可防止在ajax过程中多次单击:

$( "button" ).click(function() {
  var obj = $(this);
  obj.attr("disabled","disabled");
  $.ajax({ 
         ... 
       success: function() {
         obj.removeAttr("disabled");
       }
  });
});
//在此处添加您的javascript
$(函数(){
变量形式=$(“.ajaxform”);
表单提交(功能(事件){
form.hide();//隐藏表单
$(“#加载指示器”).text(“加载文本”).show();
$.ajax({
类型:“POST”,
url:“addcomment.php”,
数据:$(“.ajaxform”).serialize(),//序列化表单的元素。
成功:功能(数据){
表格.show()
$(“#加载指示器”).hide();
},
错误:函数(错误){
form.show();
}
});
event.preventDefault();//避免执行表单的实际提交。
});
});
#加载指示器{
显示:无;
}

添加注释
//在此处添加您的javascript
$(函数(){
变量形式=$(“.ajaxform”);
表单提交(功能(事件){
form.hide();//隐藏表单
$(“#加载指示器”).text(“加载文本”).show();
$.ajax({
类型:“POST”,
url:“addcomment.php”,
数据:$(“.ajaxform”).serialize(),//序列化表单的元素。
成功:功能(数据){
表格.show()
$(“#加载指示器”).hide();
},
错误:函数(错误){
form.show();
}
});
event.preventDefault();//避免执行表单的实际提交。
});
});
#加载指示器{
显示:无;
}

添加注释
使用
。替换为

$( "button" ).one( "click",function() {

    $(this).replaceWith('<p>' + $(this).html() +'</p>')

})
$(“按钮”).one(“单击”,函数(){
$(this.replaceWith(''+$(this.html()+'

')) })
$(“按钮”).one(“单击”,函数(){
$(this.replaceWith(''+$(this.html()+'

')) })

添加注释

使用
。替换为

$( "button" ).one( "click",function() {

    $(this).replaceWith('<p>' + $(this).html() +'</p>')

})
$(“按钮”).one(“单击”,函数(){
$(this.replaceWith(''+$(this.html()+'

')) })
$(“按钮”).one(“单击”,函数(){
$(this.replaceWith(''+$(this.html()+'

')) })

添加注释

你不能那样做。您可以删除(或隐藏)按钮并添加(或显示)段落,但不能将DOM元素节点从一种类型转换为另一种类型。您不能这样做。您可以删除(或隐藏)按钮并添加(或显示)段落,但不能将DOM元素节点从一种类型转换为另一种类型。感谢您的回答,添加禁用的类不起作用@ILYASDATTOW
disabled
不是一个类。disabled不是类。它是一个属性,但在引导中,我们必须添加disabled类,然后像这样添加类:obj.addClass(“disabled”);感谢您的回答,添加残疾人课程不起作用@ILYASDATTOW
disabled
不是一个类。disabled不是类。它是一个属性,但在引导中,我们必须添加disabled类,然后像这样添加类:obj.addClass(“disabled”);这是无效的。因为如果php出现问题。用户必须刷新页面。在错误回调中,您可以显示表单并显示错误。这是无效的。因为如果php出现问题。用户必须刷新页面。在错误回调中,您可以显示表单并显示错误