我只是想知道是否可以得到一些指示。
我使用简写 if 来根据 div 是否切换来更改文本。
这就是我的文本更改器:
$(this).text($(this).text() == 'Email Me' ? 'Close Form' : 'Email Me');
我想按照这些思路更改 anchor 的标题属性。我已经尝试过使用以下方法:
$(this).text($(this).attr('title', == 'Email Me' ? 'Close Form' : 'Email Me')); //This throws up syntax errors in firebug because of where the == is placed
我也尝试过如下:
$(this).text($(this).attr('title') == 'Email Me' ? 'Close Form' : 'Email Me'); //This doesn't change the attribute at all.
我想我可能真的很蠢,但我无法弄清楚这一点。我用谷歌搜索了一下,似乎找不到明确的答案。
只是想知道您是否对我可能出错的地方有任何建议。
提前致谢
最佳答案
您不应该使用 attr
来代替吗?
$(this).attr("title", $(this).attr('title') == 'Email Me' ? 'Close Form' : 'Email Me');
而不是:
$(this).text($(this).attr('title') == 'Email Me' ? 'Close Form' : 'Email Me'); //This doesn't change the attribute at all.
关于jquery - 使用简写 if 更改属性时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16801736/