简体   繁体   English

内部jQuery在chrome,IE,FF中不起作用

[英]Internal jQuery doesn't work in chrome, IE, FF

The jQuery code below does work when I open the preview editor from Aptana Studio 3. Unfortunately, the jQuery doesn't work when I open my webpage with Chrome, IE or FF 当我从Aptana Studio 3打开预览编辑器时,下面的jQuery代码可以工作。不幸的是,当我使用Chrome,IE或FF打开网页时,jQuery不起作用。

<script>
        $(document).ready(function() {
            $('input[type="text"],input[type="password"],select,:submit').addClass("idleField");  
            $('input[type="text"],input[type="password"],select').focus(function() {  
                $(this).removeClass("idleField").addClass("focusField");  
                if (this.value == this.defaultValue){  
                    this.value = '';  
                }
                if(this.value != this.defaultValue){  
                    this.select();  
                }  
            });

            $('input[type="text"],input[type="password"],select').blur(function() {  
                $(this).removeClass("focusField").addClass("idleField");  
                if ($.trim(this.value == '')){
                    this.value = (this.defaultValue ? this.defaultValue : this.value);  
                }
            });

            $('#DOBM,#DOBY').change(function() {
                if ($('#DOBM').val() == '04'||$('#DOBM').val() == '06'||$('#DOBM').val() == '09'||$('#DOBM').val() == '11') {
                    $("#DOBD option[value='31']").remove();
                    if ($("#DOBD option[value='29']").length == 0){
                        $("#DOBD").append("<option value='29'>29</option>");
                    }
                    if ($("#DOBD option[value='30']").length == 0){
                        $("#DOBD").append("<option value='30'>30</option>");
                    }
                }
                if ($('#DOBM').val() == '01'||$('#DOBM').val() == '03'||$('#DOBM').val() == '05'||
                $('#DOBM').val() == '07'||$('#DOBM').val() == '08'||$('#DOBM').val() == '10'||$('#DOBM').val() == '12'){
                    if ($("#DOBD option[value='29']").length == 0){
                        $("#DOBD").append("<option value='29'>29</option>");
                    }
                    if ($("#DOBD option[value='30']").length == 0){
                        $("#DOBD").append("<option value='30'>30</option>");
                    }
                    if ($("#DOBD option[value='31']").length == 0){
                        $("#DOBD").append("<option value='31'>31</option>");
                    }
                }
                if ($('#DOBM').val() == '02'){
                    $("#DOBD option[value='31']").remove();
                    $("#DOBD option[value='30']").remove();
                    $("#DOBD option[value='29']").remove();
                    if (($('#DOBY').val() % 4 == 0)&&($('#DOBY').val() % 100 != 0)||($('#DOBY').val() % 400 == 0)){
                        $("#DOBD").append("<option value='29'>29</option>");
                    }
                }
            })
        })
    </script>

Does someone have an idea why it doesn't work? 有人知道为什么它不起作用吗? I'm new to programming and any help/advice is really appreciated. 我是编程的新手,真的很感谢任何帮助/建议。 Thanks! 谢谢!

Edit: this is what should happen on fiddle: 编辑:这是应该在小提琴上发生的事情:

The first two blocks of jQuery were written to change the CSS on the form inputs. 编写了jQuery的前两个块,以更改表单输入上的CSS。 On focus, the inputs will change to "focusField", and therefore will have new CSS properties that are in the .css file. 在焦点上,输入将更改为“ focusField”,因此将具有.css文件中的新CSS属性。 On blur, it changes back to class "idleField". 模糊时,它变回类“ idleField”。

If the user hasn't typed in the input, the default value comes back. 如果用户未输入输入,则返回默认值。 If the user has typed something, it keeps his input. 如果用户键入了某些内容,它将保留其输入。 This DOES work. 这确实起作用。

The rest of my jQuery code is to update the number of days in a month. 我其余的jQuery代码将更新一个月中的天数。 If month selected is 04||06||09||11, then delete day 31 and append days 29,30 if they don't exist. 如果选择的月份是04 || 06 || 09 || 11,则删除第31天,如果不存在则添加第29,30天。 If month selected is 01||03||05||07||08||10||12, then append days 29,30,31 if they don't exist. 如果选择的月份是01 || 03 || 05 || 07 || 08 || 10 || 12,则添加不存在的第29、30、31天。 The last block is for February (02). 最后一块是二月(02)。 Remove days 31,30,29. 删除第31、30、29天。 If leap year, append day 29. 如果是leap年,请附加第29天。

I changed few things in your fiddle and it's now working 我在您的提琴中做了几处更改,现在可以了

See if this is what you want 看看这是不是你想要的

Fiddle 小提琴

  • You had unnecessary brackets at the end }) 末尾有不必要的括号})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery在FF或IE中不起作用,但在Chrome中可以正常工作 - jQuery doesn't work in FF or IE but works fine in Chrome 简单的JQuery在Chrome中不起作用,FF在IE6上有效 - Simple JQuery doesn't work in Chrome ,FF works on IE6 jQuery AJAX发布请求不适用于IE或FF-在Chrome中正常运行 - JQuery AJAX Post request doesn't work in IE or FF - Works fine in Chrome iframe中生成的jQuery代码在IE中不起作用,但在FF和Chrome中有效 - Generated jQuery code in iframe doesn't work in IE but works in FF and Chrome 在IE 9之前无法使用的Javascript / jquery代码在FF,Chrome,Safari中正常运行 - Javascript/jquery code that doesn't work prior to IE 9. Works fine in FF, Chrome, Safari jQuery scrollTop不会在FF或IE中创建动画,但在chrome中可以正常工作 - jQuery scrollTop doesn't animate in FF or IE but working fine in chrome .animate()在IE10中不起作用,但在IE9,IE8,IE7,Chrome和FF中起作用 - .animate() doesn't work in IE10 but works in IE9, IE8, IE7, Chrome, and FF 为什么这个jQuery可以在Chrome中运行,但不能在FF或IE中运行? - Why would this jQuery work in Chrome but not FF or IE? jQuery load()在IE和Chrome上不起作用 - jQuery load() doesn't work on IE and Chrome <a href doesn't fire after .Click jquery function call in IE. Works fine with Chrome and FF - <a href doesn't fire after .Click jquery function call in IE. Works fine with Chrome and FF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM