JavaScript函数不适合我

时间:2018-03-04 19:08:19

标签: javascript jquery onclick

即便是这个简单的似乎也不起作用,我也没有任何世俗的想法。 我试图删除该课程,但这并不重要,因为无论我试图做什么都不行。我想知道原因。

这是我的css:

#include <iostream>
#include <vector>
#include <type_traits>

void print(std::ostream& out) {}

template <typename T, typename... Args>
void print(std::ostream& out, T type, Args... args) 
{
    if (std::is_same<T, std::vector<int>>::value) {
        for (auto vector_iterator = type.begin();
            vector_iterator != type.end(); ++vector_iterator) {
            out << (*vector_iterator) << " ";
        }
    } else {
        out << type;
    }
    print(out, args...);
}


int main()
{
    std::vector<int> v {4,5,6};

    print(std::cout, "bla", 1, 23.0, v);
    return 0;
}

这是我的JavaScript:

util.cc: In instantiation of 'void print(std::ostream&, T, Args ...) [with T = const char*; Args = {int, double, std::vector<int, std::allocator<int> >}; std::ostream = std::basic_ostream<char>]':
util.cc:26:36:   required from here
util.cc:11:42: error: request for member 'begin' in 'type', which is of non-class type 'const char*'
   for (auto vector_iterator = type.begin();
                                          ^
util.cc:12:20: error: request for member 'end' in 'type', which is of non-class type 'const char*'
    vector_iterator != type.end(); ++vector_iterator) {

2 个答案:

答案 0 :(得分:0)

我相信您正在尝试从元素中删除其中一个类

选择元素 - 有多种方法可以做到这一点,

  • Document.getElementsByClassName()
  • Document.getElementsByTagName()
  • document.getElementById(String id)
  • document.getElementsByName()

使用getElementById()将选出一个非常具体的元素,

<i id="italics-slider" onclick="removeClass()" class="fas fa-bars slide"></i>
function removeClass() {
   var icon = document.getElementById("italics-slider");
   icon.classList.remove("fa-bars");
}

答案 1 :(得分:-1)

HTML

<i id="slide" onClick="removeClass(this)" class="fas fa-bars slide">X</i>

的JavaScript

function removeClass(element) {
  element.classList.remove('slide')
}