Javascript 是否将按钮更改为html表中的链接?
我的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
@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
名称,而是将classnamebtnExtend
(您命名),并为其注册单击处理程序,如下所示:
$(文档).on('click','btnExtend',function(){
$(this.text)($(this.text()='Extend'?'unextended':'Extend');
});代码>
扩展您的意思是将按钮标记更改为a
标记吗
由于按钮元素在循环迭代中,您不能使用相同的ID
名称,而是将classnamebtnExtend
(您命名),并为其注册单击处理程序,如下所示:
$(文档).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()的
}
延伸
}
我喜欢这个评论。用歌声来爱这篇评论。吟诗