Wordpress Javascript问题
我对Javascript相当陌生,对Wordpress也非常陌生。我正在创建一个主题,并设法使除JavaScript之外的所有内容都正常工作。它在没有Wordpress的情况下工作得很好,但它似乎不工作。我已经阅读了其他一些关于Wordpress、Javascript的正确格式的文章,但仍然无法实现。这是我的剧本,有人能给我指出正确的方向吗?我绝望了Wordpress Javascript问题,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,我对Javascript相当陌生,对Wordpress也非常陌生。我正在创建一个主题,并设法使除JavaScript之外的所有内容都正常工作。它在没有Wordpress的情况下工作得很好,但它似乎不工作。我已经阅读了其他一些关于Wordpress、Javascript的正确格式的文章,但仍然无法实现。这是我的剧本,有人能给我指出正确的方向吗?我绝望了 (function ( $ ) { $('input:radio[name="name"]').change(function(){
(function ( $ ) {
$('input:radio[name="name"]').change(function(){
if($(this).val() == 'Month to Month'){
$( "#checkout-button" ).before( "<input type=\"hidden\" name=\"price\" value=\"12.00\"<\/input>");
}if($(this).val() == 'Month to Month - Hello Giggles'){
$( "#checkout-button" ).before( "<input type=\"hidden\" name=\"price\" value=\"12.00\"<\/input>");
}
});
$(".imgLiquidFill").imgLiquid({fill:true, horizontalAlign:'center', verticalAlign:'center'});
$(".youtube").colorbox({iframe:true, innerWidth:640, innerHeight:390});
$(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
$(".inline").colorbox({inline:true, width:"50%"});
$(".radio-duration").click(function() {
$(".duration-button").html("Select\<span class\=\"fui\-arrow\-right\"\>\<\/span\>");
$(this).children(".duration-button").text("Selected");
$('.radio-duration').not(this).stop().animate({
opacity: 0.4
}, 150);
// Make this opaque
$(this).stop().animate({
opacity: 1.0
}, 150);
});
$(".radio-gender").click(function() {
$(".gender-button").html("Select\<span class\=\"fui\-arrow\-right\"\>\<\/span\>");
$(this).children(".gender-button").text("Selected");
$('.radio-gender').not(this).stop().animate({
opacity: 0.4
}, 150);
$(this).stop().animate({
opacity: 1.0
}, 150);
});
$(".radio-style").click(function() {
$(".check-style").css("color", "#1abc9c");
$(".check-style").css("display", "inline-block");
$(".style-button").html("Select\<span class\=\"fui\-arrow\-right\"\>\<\/span\>");
$(this).children(".style-button").text("Selected");
$('.radio-style').not(this).stop().animate({
opacity: 0.4
}, 150);
// Make this opaque
$(this).stop().animate({
opacity: 1.0
}, 150);
});
$(".duration-container :radio").hide().click(function(e){
e.stopPropagation();
});
$(".duration-container div").click(function(e){
$(this).closest(".duration-container").find("div").removeClass("selected-div");
$(this).addClass("selected-div").find(":radio").click();
});$(".duration-container :radio").hide().click(function(e){
e.stopPropagation();
});
$(".duration-container div").click(function(e){
$(this).closest(".duration-container").find("div").removeClass("selected-div");
$(this).addClass("selected-div").find(":radio").click();
});
$(".gender-container :radio").hide().click(function(e){
e.stopPropagation();
});
$(".gender-container div").click(function(e){
$(this).closest(".gender-container").find("div").removeClass("selected-div");
$(this).addClass("selected-div").find(":radio").click();
});$(".gender-container :radio").hide().click(function(e){
e.stopPropagation();
});
$(".gender-container div").click(function(e){
$(this).closest(".gender-container").find("div").removeClass("selected-div");
$(this).addClass("selected-div").find(":radio").click();
});
$(".style-container :radio").hide().click(function(e){
e.stopPropagation();
});
$(".style-container div").click(function(e){
$(this).closest(".style-container").find("div").removeClass("selected-div");
$(this).addClass("selected-div").find(":radio").click();
});$(".style-container :radio").hide().click(function(e){
e.stopPropagation();
});
$(".style-container div").click(function(e){
$(this).closest(".style-container").find("div").removeClass("selected-div");
$(this).addClass("selected-div").find(":radio").click();
});
var num = 10; //number of pixels before modifying styles
if ($(window).width() > 767) {
$(window).bind('scroll', function($) {
if ($(window).scrollTop() > num) {
$('.navbar').addClass('navbar-condensed');
$('.navbar .navbar-brand').addClass('navbar-brand-condensed');
$('.navbar-nav').addClass('navbar-nav-condensed');
} else {
$('.navbar').removeClass('navbar-condensed');
$('.navbar .navbar-brand').removeClass('navbar-brand-condensed');
$('.navbar-nav').removeClass('navbar-nav-condensed');
}
});
}
//TESTIMONIALS
function fade($ele) {
$ele.fadeIn(1000).delay(2000).fadeOut(1000, function() {
var $next = $(this).next('.a-testimonial');
fade($next.length > 0 ? $next : $(this).parent().children().first());
});
}
fade($('#testimonials > .a-testimonial').first());
});
(函数($){
$('input:radio[name=“name”]”)。更改(函数(){
if($(this).val()=='逐月'){
$(“#签出按钮”)。在(“加载主题中的脚本文件之前。这是WordPress包含JavaScript的首选方式。如果使用JQuery,则应在JQuery文件的开头执行此操作:
jQuery(document).ready(function($){<--- notice the $ inside the function()? This will allow your code to work
//your code here
}
请注意,您必须这样定义它,因为Wordpress在无冲突模式下运行。您检查了console吗?可能您在那里得到的信息会help@KaiQing是的,我检查过了,没有任何错误。PHP到底适合什么?好吧,js和wordpress并不是真的相互关联,只是wordpress有自己的方式f将js添加到页眉或页脚。您可以直接将其添加到header.php或footer.php中,但为了让我们知道您的主要问题是什么,我们可能需要了解您如何包含依赖项.jQuery、colorbox等,甚至您如何管理html。据我们所知,您正在动态添加到dom中。我认为我们无法我只是从您提供的这段代码中获得的。谢谢。我的排队脚本工作正常,但实际脚本有问题。@user2793640请查看我的编辑。这至少可以让您继续工作。我不能保证所有代码都能工作,但至少可以让您继续工作。谢谢。我的排队脚本工作正常,但act有问题色情剧本。
var $j = jQuery.noConflict();
$j(function(){
//your code here
});