数据肘节="崩"单击它时菜单消失

时间:2018-03-20 22:26:03

标签: css twitter-bootstrap drop-down-menu

单击时,我的data-toggle="collapse"菜单会消失。

虽然它确实按需要下拉,但只要用户点击下拉菜单中的任何位置,它就会消失。

我做错了什么?这是我的代码:

 <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle bg-dark " href="#" id="navbarDropdown1" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    My Account
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">Other info goes here... //before the closing div

1 个答案:

答案 0 :(得分:0)

您需要添加func addBookingRow(firstTime: Bool) { let containerView = UIView() containerView.backgroundColor = .white containerView.layer.cornerRadius = 5 containerView.layer.borderColor = .white containerView.layer.borderWidth = 2 containerView.tag = count contentView.addSubview(containerView) containerView.translatesAutoresizingMaskIntoConstraints = false if firstTime { containerView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10).isActive = true } else { containerView.topAnchor.constraint(equalTo: bookedServices[count - 1].bottomAnchor, constant: 10).isActive = true } containerView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16).isActive = true containerView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16).isActive = true let serviceNameTF = CustomTextField() serviceNameTF.backgroundColor = .white serviceNameTF.placeholder = "Choose Service" serviceNameTF.font = UIFont(name: "RB", size: 17) serviceNameTF.textAlignment = .right serviceNameTF.tag = count containerView.addSubview(serviceNameTF) setupPickerViews(textField: serviceNameTF, picker: serviceNamePicker) serviceNameTF.addTarget(self, action: #selector(self.serviceNameIsTapped), for: .touchDown) serviceNameTF.translatesAutoresizingMaskIntoConstraints = false serviceNameTF.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 5).isActive = true serviceNameTF.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 5).isActive = true serviceNameTF.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -5).isActive = true serviceNameTF.heightAnchor.constraint(equalToConstant: 40).isActive = true let workerTF = CustomTextField() workerTF.backgroundColor = .white workerTF.placeholder = "Choose Servant" workerTF.font = UIFont(name: "RB", size: 17) workerTF.textAlignment = .right workerTF.tag = count containerView.addSubview(workerTF) setupPickerViews(textField: workerTF, picker: workerPicker) workerTF.addTarget(self, action: #selector(self.workerTFIsTapped), for: .touchDown) workerTF.translatesAutoresizingMaskIntoConstraints = false workerTF.topAnchor.constraint(equalTo: serviceNameTF.bottomAnchor, constant: 5).isActive = true workerTF.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 5).isActive = true workerTF.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -5).isActive = true workerTF.heightAnchor.constraint(equalToConstant: 40).isActive = true let price = UILabel() price.font = UIFont(name: "RB", size: 17) price.textColor = .white containerView.addSubview(price) price.translatesAutoresizingMaskIntoConstraints = false price.topAnchor.constraint(equalTo: workerTF.bottomAnchor, constant: 5).isActive = true price.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 5).isActive = true price.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -5).isActive = true price.heightAnchor.constraint(equalToConstant: 40).isActive = true containerView.bottomAnchor.constraint(equalTo: price.bottomAnchor, constant: 5).isActive = true contentView.bottomAnchor.constraint(greaterThanOrEqualTo: containerView.bottomAnchor, constant: 250).isActive = true bookedServices.append(containerView) count += 1 } 属性,以便Bootstrap知道要删除哪一个。

data-target