设置display =' block';

时间:2015-05-13 23:04:25

标签: javascript html css angularjs twitter-bootstrap

它适用于尚未隐藏的div,但我从显示设置为无开始。

HTML

<div class="container-fluid">
    <div class="row">
        <button class ="col-md-6" ng-click="showAssessments()">Product Groups</button>
        <button class="col-md-6" ng-click="showSkills()">Skills</button>
    </div>
</div>

<ng-include src="detailsTemplate"></ng-include>
<ng-include src="skillsTemplate" style="display:none"></ng-include>
</div>

detailsTemplate的html(这些是部分视图)

<form ng-submit="submit()" name="assessmentForm"  id="assessmentForm">
    <!-- TODO: don't use table for layout -->
    <table class="table table-striped table-bordered" assessment-input-tabber>
      //......
    </table>
</form>

技能模板的html

<form ng-submit="submit()" id="skillsTable">
    <table class="table table-striped table-bordered" assessment-input-tabber>
       ......
    </table>
</form>

这是我的controller.js函数

       $scope.showSkills = function(){
            document.getElementById('assessmentForm').style.display = 'none';
            document.getElementById('skillsTable').style.display = "block";
        };

        $scope.showAssessments = function(){
            document.getElementById('skillsTable').style.display = "none";
            document.getElementById('assessmentForm').style.display = "block";
        };

如果我没有在ng-include src =&#34; skillTemplate&#34;中将显示设置为无...它工作正常,除了它第一次显示在我的assessmentForm下面并且没有离开,直到我点击其中一个按钮。

如何让它第一次隐藏技能表,然后在点击时显示?

1 个答案:

答案 0 :(得分:0)

不要对import UIKit class ViewController: UIViewController, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource { let searchController = UISearchController(searchResultsController: nil) var tableView = UITableView() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.searchController.searchResultsUpdater = self self.searchController.delegate = self self.searchController.searchBar.delegate = self self.searchController.hidesNavigationBarDuringPresentation = true self.searchController.dimsBackgroundDuringPresentation = true tableView.dataSource = self tableView.delegate = self self.navigationItem.titleView = searchController.searchBar self.definesPresentationContext = true self.setupSearchBar() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func updateSearchResultsForSearchController(searchController: UISearchController) { } func setupSearchBar() { // Set search bar position and dimensions var searchBarFrame: CGRect = self.searchController.searchBar.frame var viewFrame = self.view.frame self.searchController.searchBar.frame = CGRectMake(searchBarFrame.origin.x, searchBarFrame.origin.y + 64,viewFrame.size.width, 44) // Add search controller's search bar to our view and bring it to forefront self.view.addSubview(self.searchController.searchBar) } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = UITableViewCell() return cell } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 5 } } 上的style="display:none"进行硬编码,请尝试使用ng-includeng-show作为@PetrAveryanov建议:

HTML:

ng-hide

detailsTemplate:

<ng-include src="detailsTemplate"></ng-include>
<ng-include src="skillsTemplate"></ng-include>

skillsTemplate:

<form ng-submit="submit()" name="assessmentForm"  id="assessmentForm" ng-show="assessmentForm">
...

然后,在您的控制器中,使用:

<form ng-submit="submit()" id="skillsTable" ng-show="skillsTable">
...