javascript - 在 .each 中排除一个元素

标签 javascript jquery

如何遍历所有文本区域,不包括我有 id 的文本区域?

$("textarea").each(function (i, v) {
    // i could use an "if" inside here, but would rather adjust the selector
});

我试过使用 :not($('#mySpecialTextarea')),但无法正常工作。

最佳答案

使用 jquery .not()

$("textarea").not('#mySpecialTextarea').each(function (i, v) {
    // your code
});

DEMO

您还可以使用 :not()

$("textarea:not('#mySpecialTextarea')").each(function (i, v) {
    // your code
});

DEMO

The .not() method will end up providing you with more readable selections than pushing complex selectors or variables into a :not() selector filter. In most cases, .not() is a better choice.

关于javascript - 在 .each 中排除一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32375689/

相关文章:

php - $(window).unload 中的killSession() PHP 函数

javascript - 使用 Angular 简单上一个\下一个 slider

javascript - 对象数组的客户端全文搜索

jquery - 有没有 jquery 可以让 css Shadow-roundedcorners 在 IE6 及以上版本上工作

php - 如何在 PHP 中快速开发 MySQL 表的可排序、分页数据网格?

javascript - 浮起来的行

javascript - Knockout JS - 模态表单与 Bootstrap 配合不佳

javascript - 使用 Javascript 替换 HTML 中的 href 文本

javascript - JavaScript 中变量的作用域是什么?

jquery - 将图像的比例从 100vh 动画化到 100% 宽度