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