Firefox处理xxx.submit(),Safari不...可以做什么? [英] Firefox handles xxx.submit(), Safari doesn't ... what can be done?

查看:132
本文介绍了Firefox处理xxx.submit(),Safari不...可以做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户从菜单中的一个选项中选择(释放鼠标)时,我正在尝试下拉菜单。此代码在FF中正常工作,但由于某些原因,Safari不会提交表单。我使用jquery重新编写代码,看看jquery的.submit()实现是否更好地处理了浏览器的怪癖。相同的结果,在FF工作不适用于野生动物园。

I'm trying to make a pull down menu post a form when the user selects (releases the mouse) on one of the options from the menu. This code works fine in FF but Safari, for some reason, doesn't submit the form. I re-wrote the code using jquery to see if jquery's .submit() implementation handled the browser quirks better. Same result, works in FF doesn't work in safari.

以下代码片段来自同一页面,其中包含一些django模板语言。

The following snippets are from the same page, which has some django template language mixed in.

这是香草js尝试:

function formSubmit(lang) {
    if (lang != '{{ LANGUAGE_CODE }}') {
        document.getElementById("setlang_form").submit();
    }
}

以下是jquery尝试:

Here's the jquery attempt:

$(document).ready(function() {
    $('#lang_submit').hide()
    $('#setlang_form option').mouseup(function () { 
        if ($(this).attr('value') != '{{ LANGUAGE_CODE }}') { 
            $('#setlang_form').submit()
        } 
    });
});

,其格式如下:

<form id="setlang_form" method="post" action="{% url django.views.i18n.set_language %}">
    <fieldset>
    <select name="language">
    {% for lang in interface_languages %}
        <option value="{{ lang.code }}" onmouseup="formSubmit('{{ lang.name }}')" {% ifequal lang.code LANGUAGE_CODE %}selected="selected"{% endifequal %}>{{ lang.name }}</option>
    {% endfor %}
    </select>
    </fieldset>
</form>

我的问题是,我该如何在Safari中获得这项工作?

My question is, how can I get this working in Safari?

推荐答案

代码将是:

<form id="setlang_form" method="post" action="{% url django.views.i18n.set_language %}">
    <fieldset>
    <select name="language" onchange="formSubmit(this)">
    {% for lang in interface_languages %}
        <option value="{{ lang.code }}" {% ifequal lang.code LANGUAGE_CODE %}selected="selected"{% endifequal %}>{{ lang.name }}</option>
    {% endfor %}
    </select>
    </fieldset>
</form>

要获取值:

function formSubmit(theForm)
{
 .... theForm.options[theForm.selectedIndex].value
}

您可以使用jquery:

You can do it with jquery too:

$(document).ready(function() {
    $('#lang_submit').hide()
    $('#setlang_form select').change(function () { 
        ....     $("select option:selected").text() ....  
        } 
    });
});

使用Jquery查看更改事件:
http://docs.jquery.com/Events/change

Look here to know about change event with Jquery: http://docs.jquery.com/Events/change

这篇关于Firefox处理xxx.submit(),Safari不...可以做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆