这是我的输入:
<a id="choose" alt="554">Choose</a>
如何在单击链接“选择”后变为“选择”并在再次单击后返回“选择”后获得输出?
我的预期输出:
<a id="choose" alt="554">Choosen</a>
这是我的 Ajax:
$(function(){
$('#choose').live('click',function(){
var $this = $(this);
var chapter_id = $this.attr('alt');
if($this.hasClass('edu_level_active')){
del_chapter(chapter_id,$this);
}else{
if($this.hasClass('disabled')){
return false;
}else{
ins_chapter(chapter_id,$this);
}
}
});
});
function ins_chapter(chapter_id,$this)
{
$.ajax({
type : 'post',
url : '/dashboard/choose/',
data : 'chapter_id:'+chapter_id,
beforeSend: function(){
$this.addClass('edu_level_active');
},error : function(){
alert('error');
}
});
return false;
}
最佳答案
您可以定义一个 bool 变量来指示单击或取消单击。
var retVal = false
$('#choose').on('click', function(){
if (!retVal){
retVal = true;
$(this).text('Choosen');
}
else {
retVal = false;
$(this).text('Choose');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a id="choose" alt="554">Choose</a>
关于javascript - 如何将链接值从 "Choose"更改为 "Chosen"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29136339/