Javascript:更改两个按钮之间的文本值

时间:2017-09-21 00:18:46

标签: javascript jquery html button

我有一些按钮。像这样:

one
two
three
four
five
six

如果点击twosix,订单会更改为:

one
six
three
four
five
two

1 个答案:

答案 0 :(得分:0)

我这样做了:



$(document).ready(function(){
var change ="a";
$("button").bind("click",function(){
if(change == "a"){
$(this).attr("id",change);
change =$(this).text();
}else{
$("#a").text($(this).text());
$(this).text(change);
change ="a";
$("#a").removeAttr("id");
} }) 
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<button>one</button>
<button>two</button>
<button>three</button>
<button>four</button>
<button>five</button>
<button>six</button>
&#13;
&#13;
&#13;