[英]How to toggle the anchor text using Jquery?
Here is my HTML code: 这是我的HTML代码:
<label for="LoginControl">
<a href="login/" class="concealed noOutline"> Log in or Sign up </a>
</label>
I need to replace the text Log in or Sign up with X when it is clicked and return to old text when clicked again. 我需要在单击时替换文本登录或使用X注册,并在再次单击时返回旧文本。
You'll need a click handler for your anchor: 你需要一个锚的点击处理程序:
$("a.concealed").click(function() {
Now you'll need some logic: 现在你需要一些逻辑:
$(this).text() == "X" ? "Log in or Sign up" : "X"; //if it equals X, return Log. Else X.
Now just combine into a function: 现在只需组合成一个函数:
$("a.concealed").click(function() {
var newText = $(this).text() == "X" ? "Log in or Sign up" : "X";
$(this).text(newText);
});
Demo: http://jsfiddle.net/afuub/ 演示: http : //jsfiddle.net/afuub/
HTML HTML
<label for="LoginControl">
<a href="login/" class="concealed noOutline"> Log in or Sign up </a>
</label>
JQUERY JQUERY
$('label a').click(function(
$(this).toggle(
function(){$(this).text('X')},
function(){$(this).text('Login or Sign Up')}
)}
Read more on Jquery Toggle http://api.jquery.com/toggle/ 阅读更多关于Jquery Toggle http://api.jquery.com/toggle/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.