Javascript曾经工作但现在却没有

时间:2014-03-05 09:35:35

标签: javascript php jquery html codeigniter

这个javascript之前有效,但就在今天,它没有。我尝试在functions.js中添加alert(),但它不再弹出。我的javascript已启用,并且也启用了弹出窗口。

footer.php

<script type="text/javascript" src="<?php echo site_url('assets/js/jquery/jquery-1.11.0.min.js') ?>"></script>
<script type="text/javascript" src="<?php echo site_url('assets/js/jquery/functions.js') ?>"></script>
<script type="text/javascript" src="<?php echo site_url('assets/js/jquery/jquery.validate.js') ?>"></script>
<script type="text/javascript" src="<?php echo site_url('assets/js/jquery/additional-methods.js') ?>"></script>

functions.js

$("document").ready(function(){
alert("sfs");
$('#type').change(function () {
    if ($('#type').val() == 'fund') {
        $('#fund').show();
        $('#submit').show();
    } else if ($('#type').val() == 'attendance') {
        $('#fund').hide();
        $('#submit').show();
    } else {
        $('#fund').hide();
        $('#submit').hide();
    }
});
$("addmember").validate({
    rules: {
        id: {
            required: true,
            digits: true
        }
        lname: {
            required: true
        }
        fname: {
            required: true
        }
        mname: {
            required: true
        }
        contact: {
            digits: true
        }
        email: {
            email: true
        }

    }
});

});

tnew.php

<div id="content">
<center>
<h1>New Transaction</h1>
<?php echo form_open("home/transact"); ?>
<table>
    <tbody>
    <tr>
        <td>Name:</td>
        <td><input type="text" placeholder="Transaction" name="name" id="name" required/></td>
    </tr>
    <tr>
        <td>Type:</td>
        <td><?php 
                $options = array(
                    'select' => '(Select Type)',
                    'fund'  => 'Funds',
                    'attendance'    => 'Attendance'
                );
                $id = 'id = "type"';
                echo form_dropdown('type', $options, 'select', $id);
            ?>
        </td>
    </tr>
    <tr id="fund" style="display: none;">
        <td>Amount: </td>
        <td><input type="number" placeholder="Amount" name="amt" id="amt" /></td>
    </tr>
    <tr id="submit" style="display: none;">
        <td colspan = 2><?php echo form_submit("submit", "Add Transaction"); ?></td>
    </tr>
    </tbody>
</table>
</center>

下拉曾经工作,但现在,它没有。如果这是一个问题,我也在使用codeigniter。

3 个答案:

答案 0 :(得分:2)

site_url使用index.php返回网址。所以你的js路径可能会抛出404错误。你应该使用base_url。

<script type="text/javascript" src="<?php echo base_url('assets/js/jquery/jquery-1.11.0.min.js') ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery/functions.js') ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery/jquery.validate.js') ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery/additional-methods.js') ?>"></script>

答案 1 :(得分:1)

看起来您的规则缺少字段配置之间的逗号(,),它应该是

$("addmember").validate({
    rules: {
        id: {
            required: true,
            digits: true
        },
        lname: {
            required: true
        },
        fname: {
            required: true
        }
        mname: {
            required: true
        },
        contact: {
            digits: true
        },
        email: {
            email: true
        }

    }
});

答案 2 :(得分:0)

尝试此声明$(document).ready(function(){});