好的,我有一个<a
调用切换函数来删除 <td
的标签标签。在那a
我有标签<<
...<<
在函数中我想更改 <<
至>>
当执行切换时。它不起作用。我做错了什么?
html:
<td class="filter_td" id="filter_td">
<td class="show_hide">
<a href="javascript:toggleFilters();" id="show_hide" alt="Hide Filters" title="Hide Filters"><<</a>
</td>
jquery:
function toggleFilters()
{
var td = $("#filter_td");
td.toggle('slow');
if (td.css("display") == "none")
{
$("#show_hide").html(">>").attr('title', 'Show Filters');
}
else
{
$("#show_hide").html("<<").attr('title', 'Hide Filters');
}
}
最佳答案
将更改文本的代码放入“toggle”的回调中。这样,您就知道动画已完成并且元素的可见状态已完成。像这样的事情:
var td = $("#filter_td");
td.toggle('slow', function () {
if (td.not(":visible"))
{
$("#show_hide").html(">>").attr('title', 'Show Filters');
}
else
{
$("#show_hide").html("<<").attr('title', 'Hide Filters');
}
});
另外,我将其隐藏检查更改为 jQuery 的“.not()”。这是判断元素在页面上是否实际可见的更通用方法,而不是简单地查看其样式(可能未定义)。
关于javascript - jQuery 在切换期间更改 'a' 标签的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12179079/