没有按钮

时间:2017-12-02 16:25:31

标签: javascript jquery twitter-bootstrap

我正在尝试使用以下代码暂停旋转木马:

$('#carousel').carousel("pause");

然而,这不起作用。当我把它放在这样一个按钮的函数中时:

$("#myBtn2").click(function(){
    $("#carousel").carousel("pause");
});

有效!为什么是这样?如何在不按按钮的情况下让它工作?!

2 个答案:

答案 0 :(得分:0)

尝试:

$( window ).on( "load", function() {
      $('#carousel').carousel("pause");
});

答案 1 :(得分:0)

不应该是:

import UIKit

class StundenplanCollectionViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationController?.navigationBar.prefersLargeTitles = false
        navigationController?.navigationBar.prefersLargeTitles = true
        navigationItem.largeTitleDisplayMode = .always

        myHours.append(myH0)
        myHours.append(myH1)
        myHours.append(myH2)
        myHours.append(myH3)
        myHours.append(myH4)
        myHours.append(myH5)

        collectionView.delegate = self
        collectionView.dataSource = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //MARK: Outlets
    @IBOutlet weak var collectionView: UICollectionView!

    //MARK: Variables
    var myDays = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag"]
    var myHours: [[String]] = Array() //Array that holds myH1 - myH5
    var myH0 = ["1", "2"]
    var myH1 = ["3", "4"]
    var myH2 = ["5", "6"]
    var myH3 = ["7", "8"]
    var myH4 = ["9", "10"]
    var myH5 = ["Error", "Error"]

    var headerColor: UIColor = UIColor( red: CGFloat(255/255.0), green: CGFloat(140/255.0), blue: CGFloat(60/255.0), alpha: CGFloat(1.0))


    //MARK: Table and Collection View
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return myDays.count
    }

    public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "stundenplanCollectionViewCell") as? StundenplanCollectionViewCell else { //how can I access the inner tableView? Error: Use of unresolved identifier 'tableView'
            return UICollectionViewCell()
        }

        //set data and reload inner table from outer view controller (StundenplanCollectionViewController according to your code)
        cell.dayItems = myHours[indexPath.row]
        cell.tableView.reloadData()
        //...

        return cell
    }


class StundenplanCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var tableView: UITableView!
    var dayItems: [String] = []

    override func awakeFromNib() {
        super.awakeFromNib()
        self.tableView.delegate = self    // <-- set delegates inner table
        self.tableView.dataSource = self
    }
}

extension StundenplanCollectionViewCell: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dayItems.count
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: StundenplanTableViewCell = (tableView.dequeueReusableCell(withIdentifier: "stundenplanTableViewCell") as? StundenplanTableViewCell)!
        //...
        return cell
    }
}

class StundenplanTableViewCell: UITableViewCell {
    @IBOutlet weak var titleLabel: UILabel!
}