[英]Bootstrap drop-down submit form
我无法将我的下拉值提交到我的 php 页面。
我试图通过 javascripts 制作它,但它不起作用。
这是代码`
<div class="col-md-6"><h5>Select your desired shape</h5></div>
<div class="col-md-2">
<input class="span2" id="search_type" name="search_type" type="hidden" >
<div class="btn-group" name="shape" id="shape">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" name="shape">
<span data-bind="label">Shapes</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" name="shape">
<li onclick="$('#search_type').val('sphere'); $('#submitForm').submit()"><a href="#"> Sphere</a></li>
<li><a href="#">Cylinder</a></li>
<li><a href="#">Cube</a></li>
<li><a href="#">Cuboid</a></li>
</ul>
</div>
</div>
</div>`
和表单声明是
<form action="submit.php" name="submitForm" id="submit" method="post" role="form" id="submitForm">
我无法解决它。
如果可能,请给我一些包含下拉值的引导程序表单示例。
您的代码正在运行:
<div class="col-md-6"><h5>Select your desired shape</h5></div>
<div class="col-md-2">
<input class="span2" id="search_type" name="search_type" type="hidden" >
<div class="btn-group" name="shape" id="shape">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" name="shape">
<span data-bind="label">Shapes</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" name="shape">
<li onclick="$(alert('it works!')).val('sphere'); $('#submitForm').submit()"><a href="#"> Sphere</a></li>
<li><a href="#">Cylinder</a></li>
<li><a href="#">Cube</a></li>
<li><a href="#">Cuboid</a></li>
</ul>
</div>
</div>
</div>`
开始使用 PHP 时要记住的一些事情是,如果您在本地运行,则必须在地址栏中键入地址以启动 php,您不能只打开 index.php 文件并期望 php 工作。
但同样,您的前端正在工作。 您的 PHP 已关闭。
也许添加<li onclick input type="submit" method= "post" action="phpfile" name="sphere"><a href="index.php"> Sphere</a></li>
这带来了另一个潜在的问题。 前端需要 Ajax 吗? 现在的方式是用户将提交并从您的页面重定向到新页面。 目标是将它们保留在页面上吗? 这将需要更多的文件,然后是引导索引和一些 php。
我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.