交换文本我试图做到的是什么“喜欢”jQuery的。点击()/。对(“点击” ...)我需要帮助的备用点击
$("button .toggleExcerpt)
.toggle(function FIRST() {
do first function...
} , function SECOND() {
do second function...
但因为它是过时,我不知道使用什么替代方法。香港专业教育学院尝试使用的if/else一个。对内部(“点击”,函数()...但似乎没有工作 jQuery的:
var readMore = "<span class='readMore'>read about the solution...</span>";
var readLess = "<span class='readLess'>hide full description...</span>";
//".toggleExcerpt" is an empty <button> in the HTML
$(".toggleExcerpt").append(readMore);
$(".toggleExcerpt")
.on("click", function (event) {
$(this).contents(".readMore")
.replaceWith(readLess);
console.log("readMore ran");
})
.on("click", function (event) {
$(this).contents(".readLess")
.replaceWith(readMore);
console.log("readLess ran");
})
双方的点击事件被记录到控制台,所以我知道的第一个事件正在运行,然后很快被第二个事件替换,但我很想让这些(或简单的跨度内的文本)交替....
我已经已经看了this suggestion,但我不知道如何在我的例子中实现它,也不是如果这个特定的jQuery实现是我需要的。