我不确定循环是否是正确的术语,但我有一个完美运行的产品页面。我希望能够有一个“添加产品选项按钮”,当管理员单击它时,它会向下切换,而另一个“添加产品选项按钮”会替换我刚刚打开的按钮。因此产品选项的数量是无限的,用户可以添加任意数量的产品。
<!--Restaurant toggle-->
<a id="restt" class ="header"href="#" onclick="toggleVisibility('Rest');">
<h3 id="open">Your Restaurants</h3>
</a>
<div id="Rest" class="Rest_new" style="display: none;"><div>
<ul class="tabs1">
<!--
<li id="order" class="rred">
<a href="Franchise-account-orders.php">restaurant</a>
</li>
-->
<li id="order_open" class="rgreen">
<a href="javascript:void(0);">New restaurant</a>
</li>
</ul>
</div>
</div>
<!-- add element-->
<script>
$(document).on('click', 'li#order_open', function() {
$(this).before('<li><a href="Menu.php">New restaurant</a></li>');
// add to localsorage?
window.onload = function() {}
var order_open = $('div#Rest').html();
localStorage.setItem('div#Rest', order_open);
});
</script>
我目前正在使用以下代码。它创建了无限的选项,但是我无法打开选项,我无法切换它并且它在页面刷新时消失。有没有更好的方法来做到这一点。
最佳答案
你的问题是javascript。你可以使用
$('container').append('html content');
看一个例子:
$(document).ready(function(){
$("#btn1").click(function(){
$("p").append(" <b>Appended text</b>.");
});
$("#btn2").click(function(){
$("ol").append("<li>Appended item</li>");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>
<button id="btn1">Append text</button>
<button id="btn2">Append list items</button>
关于javascript - 如何循环一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35725119/