Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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 是否将按钮更改为html表中的链接?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 是否将按钮更改为html表中的链接?

Javascript 是否将按钮更改为html表中的链接?,javascript,jquery,html,Javascript,Jquery,Html,我的html表格中有按钮。当我点击按钮时,我想将链接按钮更改为“取消扩展”,然后点击“取消扩展”切换回上一个按钮。我该怎么做? @foreach(模型中的var项目) { @item.MemberCustomerName @item.PositionCodeDescription @item.MemberMaster客户 @item.MemberCustomerEmail @如果(item.EndDate!=null) { @item.EndDate.Value.ToShortDateStr

我的html表格中有按钮。当我点击按钮时,我想将链接按钮更改为“取消扩展”,然后点击“取消扩展”切换回上一个按钮。我该怎么做?


@foreach(模型中的var项目)
{
@item.MemberCustomerName
@item.PositionCodeDescription
@item.MemberMaster客户
@item.MemberCustomerEmail
@如果(item.EndDate!=null)
{
@item.EndDate.Value.ToShortDateString()的
}
延伸
}
你想要这样吗

<button id="btnExtend" type="button" class="btn btn-info btn-xs un-extended" data-toggle="modal" data-target="#saveExtend" data-value='"@item.CommitteeMasterCustomer"'>Extend</button>

    jQuery(document).on("click",".un-extended",function(){
        if(!$(this).hasClass("extend")){
            $(this).addClass("extend");
            $(this).text("Un-Extend");
        }else{
           $(this).removeClass("extend");
            $(this).text("Extend");
        }
    });
扩展
jQuery(document).on(“click”,“.un-extended”,函数(){
if(!$(this).hasClass(“扩展”)){
$(此).addClass(“扩展”);
$(此).text(“Un扩展”);
}否则{
$(此).removeClass(“扩展”);
$(此).text(“扩展”);
}
});
您想要这样吗

<button id="btnExtend" type="button" class="btn btn-info btn-xs un-extended" data-toggle="modal" data-target="#saveExtend" data-value='"@item.CommitteeMasterCustomer"'>Extend</button>

    jQuery(document).on("click",".un-extended",function(){
        if(!$(this).hasClass("extend")){
            $(this).addClass("extend");
            $(this).text("Un-Extend");
        }else{
           $(this).removeClass("extend");
            $(this).text("Extend");
        }
    });
扩展
jQuery(document).on(“click”,“.un-extended”,函数(){
if(!$(this).hasClass(“扩展”)){
$(此).addClass(“扩展”);
$(此).text(“Un扩展”);
}否则{
$(此).removeClass(“扩展”);
$(此).text(“扩展”);
}
});

您可以这样做:

$('button').click(function(){
    if($(this).text() == "Extend") {
        $(this).text('Un-Extend');
    } else {
        $(this).text('Extend');
  }
});

您可以这样做:

$('button').click(function(){
    if($(this).text() == "Extend") {
        $(this).text('Un-Extend');
    } else {
        $(this).text('Extend');
  }
});

您的意思是将
按钮
标记更改为
a
标记吗

由于按钮元素在循环迭代中,您不能使用相同的
ID
名称,而是将classname
btnExtend
(您命名),并为其注册单击处理程序,如下所示:

$(文档).on('click','btnExtend',function(){
$(this.text)($(this.text()='Extend'?'unextended':'Extend');
});


扩展
您的意思是将
按钮
标记更改为
a
标记吗

由于按钮元素在循环迭代中,您不能使用相同的
ID
名称,而是将classname
btnExtend
(您命名),并为其注册单击处理程序,如下所示:

$(文档).on('click','btnExtend',function(){
$(this.text)($(this.text()='Extend'?'unextended':'Extend');
});


扩展
您可能希望尝试此操作

$(“#btnExtend”)。在(“单击”,函数(){


}))

您可能想试试这个

$(“#btnExtend”)。在(“单击”,函数(){


}))

更改为下面的代码,并将jquery的下面功能应用到代码中:

tbody>
@foreach(模型中的var项目)
{
@item.MemberCustomerName
@item.PositionCodeDescription
@item.MemberMaster客户
@item.MemberCustomerEmail
@如果(item.EndDate!=null)
{
@item.EndDate.Value.ToShortDateString()的
}
延伸

}
更改为下面的代码,并将jquery的下面功能应用为代码:

tbody>
@foreach(模型中的var项目)
{
@item.MemberCustomerName
@item.PositionCodeDescription
@item.MemberMaster客户
@item.MemberCustomerEmail
@如果(item.EndDate!=null)
{
@item.EndDate.Value.ToShortDateString()的
}
延伸

}
我喜欢这个评论。用歌声来爱这篇评论。吟诗