我想在单击按钮时将以下按钮的添加文本更改为“删除”。
<input class="btn btn-6d" ahref="www.test.com" type="button" value="ADD"/>
我为此使用了以下jquery代码:
$(':input[type="button"][class="btn-6d"]').click(function(){
var $this = $(this);
$this.toggleClass('btn-6d');
if($this.hasClass('btn-6d')){
$this.value('ADD');
} else {
$this.value('REMOVE');
}
});
我的选择器可能做错了事,但是我对编程还比较陌生,无法弄清自己做错了什么。
这是您可以玩的小提琴:
http://jsfiddle.net/stijn777/shzuwu0v/
提前致谢,
斯蒂金
您使用value()
而不是val()
。下面的所有内容都只是一点点清理而已:)
JSFiddle:http : //jsfiddle.net/TrueBlueAussie/shzuwu0v/3/
// Find the element by the generic btn class
$(document).on('click', '.btn:input[type="button"]', function(){
var $this = $(this);
$this.toggleClass('btn-6d');
if($this.hasClass('btn-6d')){
$this.val('ADD');
} else {
$this.val('REMOVE');
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句