1

**脚本菜鸟免责声明**

在我的网站上,我希望它在联系表单中添加字段以充当我的产品的行项目,但由于某种原因,wordpress 不允许我的功能工作。这是它应该做的http://jsfiddle.net/LQ85Z/1/以及我的网站如何处理它http://ocblinds.com/order-now/。我的网站不允许显示 div。谁能看到我做错了什么?

$(function() {
$('#select').change(function() {
    if ($(this).val() == "1") {
        $('#line_1').show();
        $('#line_2').hide();
        $('#line_3').hide();
        $('#line_4').hide();
        $('#line_5').hide();
        $('#line_6').hide();
        $('#line_7').hide();
        $('#line_8').hide();
        $('#line_9').hide();
        $('#line_10').hide();

        }
    });
});
$(function() {
$('#select').change(function() {
    if ($(this).val() == "2") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').hide();
        $('#line_4').hide();
        $('#line_5').hide();
        $('#line_6').hide();
        $('#line_7').hide();
        $('#line_8').hide();
        $('#line_9').hide();
        $('#line_10').hide();
        }
    });
});
    $(function() {
    $('#select').change(function() {
    if ($(this).val() == "3") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').show();
        $('#line_4').hide();
        $('#line_5').hide();
        $('#line_6').hide();
        $('#line_7').hide();
        $('#line_8').hide();
        $('#line_9').hide();
        $('#line_10').hide();

        }
    });
});
    $(function() {
    $('#select').change(function() {
    if ($(this).val() == "4") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').show();
        $('#line_4').show();
        $('#line_5').hide();
        $('#line_6').hide();
        $('#line_7').hide();
        $('#line_8').hide();
        $('#line_9').hide();
        $('#line_10').hide();
        }
    });
});
    $(function() {
    $('#select').change(function() {
    if ($(this).val() == "5") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').show();
        $('#line_4').show();
        $('#line_5').show();
        $('#line_6').hide();
        $('#line_7').hide();
        $('#line_8').hide();
        $('#line_9').hide();
        $('#line_10').hide();
        }
    });
});
    $(function() {
    $('#select').change(function() {
    if ($(this).val() == "6") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').show();
        $('#line_4').show();
        $('#line_5').show();
        $('#line_6').show();
        $('#line_7').hide();
        $('#line_8').hide();
        $('#line_9').hide();
        $('#line_10').hide();
        }
    });
});
    $(function() {
    $('#select').change(function() {
    if ($(this).val() == "7") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').show();
        $('#line_4').show();
        $('#line_5').show();
        $('#line_6').show();
        $('#line_7').show();
        $('#line_8').hide();
        $('#line_9').hide();
        $('#line_10').hide();
        }
    });
});
    $(function() {
    $('#select').change(function() {
    if ($(this).val() == "8") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').show();
        $('#line_4').show();
        $('#line_5').show();
        $('#line_6').show();
        $('#line_7').show();
        $('#line_8').show();
        $('#line_9').hide();
        $('#line_10').hide();
        }
    });
});
    $(function() {
    $('#select').change(function() {
    if ($(this).val() == "9") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').show();
        $('#line_4').show();
        $('#line_5').show();
        $('#line_6').show();
        $('#line_7').show();
        $('#line_8').show();
        $('#line_9').show();
        $('#line_10').hide();
        }
        });
    });
        $(function() {
        $('#select').change(function() {
    if ($(this).val() == "10") {
        $('#line_1').show();
        $('#line_2').show();
        $('#line_3').show();
        $('#line_4').show();
        $('#line_5').show();
        $('#line_6').show();
        $('#line_7').show();
        $('#line_8').show();
        $('#line_9').show();
        $('#line_10').show();
        }
    });
});​
4

2 回答 2

1

您遇到的问题来自您在 orderform.js 脚本底部嵌入了非法字符:

$(function() {
    $('#select').change(function() {
        if ($(this).val() == "10") {
            $('#line_1').show();
            $('#line_2').show();
            $('#line_3').show();
            $('#line_4').show();
            $('#line_5').show();
            $('#line_6').show();
            $('#line_7').show();
            $('#line_8').show();
            $('#line_9').show();
            $('#line_10').show();
        }
    });
});​

删除它,它会正常工作。

You also seem to have embedded your javascript code inside the page itself (it's present in both the page source AND orderform.js). Remove the duplicate that's in the source code, especially that it also contains illegal characters:

<script type="text/javascript">// <![CDATA[
    $(function() {
    $('#select').change(function() {
        if ($(this).val() == "1") {
            $('#line_1').show();
            $('#line_2').hide();
            $('#line_3').hide();
            $('#line_4').hide();
            $('#line_5').hide();
            $('#line_6').hide();
            $('#line_7').hide();
            $('#line_8').hide();
            $('#line_9').hide();
            $('#line_10').hide();</p>
<p>        }
    });
});

(Notice </p> and <p>)

You can also optimize your code:

$(function() {
    $('#select').change(function() {
        var i, show = parseInt($(this).val(), 10);
        for (i = 1; i <= show; i++) {
            $('#line_' + i).show();
        }
        for (i = show; i < 10; i++) {
            $('#line_' + i).hide();
        }  
    });
});

or by using the other answer to your question (more elegant).

于 2013-01-03T00:55:30.370 回答
0

WordPress runs jQuery in no-conflict mode, so it isn't globally available as $. The following method will allow you to use $ on .ready():

jQuery(document).ready(function ($) {
  // Put your scripting here...
}); 
于 2013-01-03T01:12:50.127 回答