我尝试使用angularjs执行此操作https://jsfiddle.net/u6qdfw5f/1/但它保持空白https://jsfiddle.net/cs3rpy83/5/我看不出原因。
<title>The W3.CSS Example</title>
<body ng-app ng-init="app='accordion'">
<div class="w3-accordion w3-light-grey">
<div ng-repeat= "section in sections" ng-init="sections=['section 1','section 2']">
<button onclick="myFunction('Demo1')" class="w3-btn-block w3-left-align">
Open Section 1
</button>
<div id="Demo1" class="w3-accordion-content w3-container">
<p>Some text..</p>
</div>
</div>
</div>
</body>
答案 0 :(得分:2)
在调用ng-repeat
之前,你必须初始化部分 <div ng-init="sections=['section 1','section 2']">
<div ng-repeat= "section in sections">
<button onclick="myFunction('Demo1')" class="w3-btn-block w3-left-align">
Open Section 1
</button>
<div id="Demo1" class="w3-accordion-content w3-container">
<p>Some text..</p>
</div>
</div>