文档就绪 jquery 中的函数
function inside document ready jquery?
>我正在尝试找到一种方法将这个函数放在jQuery中的document.ready
函数中:
$('#font').change(function () {
var selectedValue2 = $(this).val();
if (selectedValue2 === 'Standard') {
$('.3Dtxt').hide();
$('.inlinetxt').hide();
} else {
if (selectedValue2 === '3D') {
$('.3Dtxt').show();
$('.inlinetxt').hide();
}
$('#' + selectedValue2).slideToggle();
} if (selectedValue2 === 'Hiline') {
$('.3Dtxt').hide();
$('.inlinetxt').show();
}
$('#' + selectedValue2).slideToggle();
});
有人可以帮我吗?
这也不起作用:
$(document).ready(function () {
$('#font').change(function () {
var selectedValue2 = $(this).val();
if (selectedValue2 === 'Standard') {
$('.3Dtxt').hide();
$('.inlinetxt').hide();
} else {
if (selectedValue2 === '3D') {
$('.3Dtxt').show();
$('.inlinetxt').hide();
}
$('#' + selectedValue2).slideToggle();
} if (selectedValue2 === 'Hiline') {
$('.3Dtxt').hide();
$('.inlinetxt').show();
}
$('#' + selectedValue2).slideToggle();
});
});
您可以在它周围包装文档就绪标签:
$(document).ready(function(){
$('#font').change(function(){
var selectedValue2 = $(this).val();
if (selectedValue2 === 'Standard') {
$('.3Dtxt').hide();
$('.inlinetxt').hide();
} else {
if (selectedValue2 === '3D') {
$('.3Dtxt').show();
$('.inlinetxt').hide();
}
$('#' + selectedValue2).slideToggle();
}if (selectedValue2 === 'Hiline') {
$('.3Dtxt').hide();
$('.inlinetxt').show();
}
$('#' + selectedValue2).slideToggle();
});
});
但是,如果您的意思是希望它在文档就绪时触发,则只需更改第一行:
$(document).ready(function(){
var selectedValue2 = $('#font').val();
if (selectedValue2 === 'Standard') {
$('.3Dtxt').hide();
$('.inlinetxt').hide();
} else {
if (selectedValue2 === '3D') {
$('.3Dtxt').show();
$('.inlinetxt').hide();
}
$('#' + selectedValue2).slideToggle();
}if (selectedValue2 === 'Hiline') {
$('.3Dtxt').hide();
$('.inlinetxt').show();
}
$('#' + selectedValue2).slideToggle();
});
也许这个?
$( document ).ready(function() {
// Your Code
});
相关文章:
- 执行ajax成功函数-jQUERY
- 函数jquery.html()不提供数据属性集值
- 将变量放入ajax函数JQuery
- 函数jquery的未定义返回
- 如何在嵌套函数jquery上保持变量的值不变
- 用我的函数jquery给出数据/参数
- Firefox在调用函数(jquery)时冻结
- 在传递节时触发一个函数 - jquery
- 循环执行数组函数jQuery
- 在函数中调用另一个函数JQuery
- 对象不是函数-Jquery/JavaScript
- TypeError:对象不是函数-jquery
- 获取函数jQuery设置的属性
- 从函数jquery获取更新的变量值
- 切换而不是悬停函数jQuery
- 函数jQuery.animation()运行了两次行,但不起作用
- 使用函数 jQuery 获取变量
- 自执行函数 jquery 与 JavaScript 的区别
- 从回调函数 -JQuery 获取返回值
- 一个接一个地执行函数 JQUERY