javascript - 使用 'this' 关键字作为选择器

标签 javascript jquery

我会使用事件的选择器来放入我的函数,但它不起作用。

我已经尝试了一些技巧,我将在下面的代码中展示。

// the actual code
$('#voyages').on('click', function() {
  if (continentOuvert == false) {
    $('#voyages i.fas.fa-arrow-up').show(500);
    $('#voyages i.fas.fa-arrow-down').hide();
  }
});

// the functions I try to make
function arrowUp() {
  $('this i.fas.fa-arrow-up').show(500);
  $('this i.fas.fa-arrow-down').hide();
}

// or
function arrowUp() {
  $(this + ' i.fas.fa-arrow-up').show(500);
  $(this + ' i.fas.fa-arrow-down').hide();
}

什么也没发生,我想我没有做对。

感谢您的帮助。

最佳答案

您可以使用find方法:

$(this).find('i.fas.fa-arrow-up').show(500);
$(this).find('i.fas.fa-arrow-down').hide();

关于javascript - 使用 'this' 关键字作为选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56236165/

相关文章:

javascript - jQuery - setInterval 与 $.each

javascript - React Native DrawerLayoutAndroid 和 Navigator 之间的冲突

javascript - 动态更改 jquery 工具提示

javascript 在 Chrome 和 Firefox 中有效,但在 IE 中无效

javascript - 从 React 元素构造 React 组件

javascript - 如何使用 jquery 添加包含 AngularJS 表达式的 ajax 加载内容

javascript - 本地机器上的 Web 服务器,有什么问题吗?

JavaScript 从数组对象中获取值不起作用

JavaScript/PHP : Open window to install twitter API then send back user info to main window

jquery - Css 和 jquery ul 和 li 菜单样式