当我向html页面添加两个脚本时..一个不起作用[关闭]

当我向html页面添加两个脚本时..一个不起作用[关闭]

问题描述:

I created two jquery and and script tags to calender an confirmation ..but when they are in seperate html pages it works well..but it doesnt work when the two scripts are in the same page..Why is that?

<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.8.21.custom.min.js" type="text/javascript"></script>
<script>

$(document).ready(function(){

 $('#click').click(function(){
    //$(function() {
        // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
        $( "#dialog:ui-dialog" ).dialog( "destroy" );

        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                "Ok": function() {

                    $('#form1').submit();
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
    });
</script>

<script type="text/javascript" src="jquery/jquery.min.js"></script>
<script type="text/javascript" src="jsdatepick-calendar/jquery.1.4.2.js"></script>
<script type="text/javascript" src="jsdatepick-calendar/jsDatePick.jquery.min.1.3.js"></script>
<script type="text/javascript" src="jquery/fadeslideshow.js"></script>

Have a look at jQueries no conflict. http://api.jquery.com/jQuery.noConflict/

This makes it so you can use certain functions from different jQuery versions/libraries.

Try reordering your scripts, it might be causing the problem. You had jQuery in multiple times, this is more than likely the cause of your problems.

Also you should try formatting your code to make it clearer what is going on. For example i have put the script type tags at the start for easier readability.

Have you specifically put Cancel with no quotes in your dialog? Ive corrected this below.

<script type="text/javascript" src="Scripts/jquery-1.7.2.min.js" ></script>
<script type="text/javascript" src="Scripts/jquery-ui-1.8.21.custom.min.js"></script>
<!--jQuery again here?--><script type="text/javascript" src="jsdatepick-calendar/jsDatePick.jquery.min.1.3.js"></script>
<script type="text/javascript" src="jquery/fadeslideshow.js"></script>    
<script type="text/javascript">

$(document).ready(function(){

    $('#click').click(function(){

        $( "#dialog:ui-dialog" ).dialog( "destroy" );

        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height: 140,
            modal: true,
            buttons: {
                "Ok": function() {
                    $('#form1').submit();
                },
                "Cancel": function() {
                    $( this ).dialog( "close" );
                }
            }
        })
    })
});
</script>

( function($$$) {

    $$$(document).ready(function(e) {
        //Code here
    });

} ) ( jQuery );