我在网站上有菜单,我使用jQuery创建一个响应式菜单,但它不起作用。这是我的代码:
// Create the dropdown base
$("<select />").appendTo("div.cssmenu");
// Create default option "Go to..."
$("<option />", {
"selected": "selected",
"value": "",
"text": "Go to..."
}).appendTo("div.cssmenu select");
// Populate dropdown with menu items
$("div.cssmenu a").each(function() {
var el = $(this);
$("<option />", {
"value": el.attr("href"),
"text": el.text()
}).appendTo("div.cssmenu select");
});
$("div.cssmenu select").change(function() {
window.location = $(this).find("option:selected").val();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cssmenu">
<ul></ul>
<select>
<option value="" selected="selected">Select</option>
<a href="index.php">
<option value="">Home</option>
</a>
<a href="about?aboutus=aboutus">
<option value="">About Us</option>
</a>
<option value="courses?cosoff=cosoff">Courses Offered</option>
<option value="admission?admi=admi">Admission</option>
<option value="facelities?face=face">Facelities</option>
<option value="events?eve=eve">Events</option>
<option value="career.php?car=car">Career</option>
<option value="contact.php?con=con">Contact</option>
</select>
</div>
我正在使用媒体查询进行响应。它工作正常,此代码工作正常,除非我从下拉列表中选择它将选择但不会重定向到指定的URL。它只是选择而没有任何反应。
我还尝试在select标记的前两个选项中使用a
标记,但它不起作用。所以任何人都可以告诉我我做错了什么。
它现在正在工作,但它显示两个下拉列表,其中有两个所有选项。
答案 0 :(得分:0)
我认为你应该只使用
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect, HttpResponseForbidden
from django.core.urlresolvers import reverse
from .models import Page, write_page
from .forms import PageForm, PageVersionForm
from ..helpers import get_pages
def update_page(request, slug):
if not request.user.has_perm("can_edit_page"):
return HttpResponseForbidden()
page = get_object_or_404(Page, slug=slug)
if request.method == "POST":
form = PageForm(request.POST)
if form.is_valid():
content = form.cleaned_data["content"]
user = request.user
write_page(name=page.name, submitter=user, content=content)
kwargs = {}
kwargs["slug"] = slug
return HttpResponseRedirect(reverse("pages:detail", kwargs=kwargs))
else:
data = {}
data["content"] = page.content
form = PageForm(data)
context = {}
page_version_form = PageVersionForm(page=page)
context["form"] = form
context["page_version_form"] = page_version_form
context["page"] = page
context["user"] = request.user
context.update(get_pages())
return render(request, "pages/page_update.html", context)
而不是以上所有代码。