dongpang2029 2016-01-13 17:02
浏览 67
已采纳

JQuery表单验证对我不起作用

I have tested this code in http://jsfiddle.net/gLpHY/92/, in there it runs fine but when I run it in my computer it does not work. (I have tested two versions of this code once using just html and jquery and the next time I use them with php, both of them did not work for me.)

<html>
<head>
    <link rel="stylesheet" href="<?php echo base_url()?>css/style.css">
    <link rel="stylesheet" href="<?php echo base_url()?>css/tableCss.css">
    <script type="text/javascript" scr="<?php echo base_url()?>js/jquery-1.12.0.js"></script>
    <script type="text/javascript" scr="<?php echo base_url()?>js/projs.js"></script>
    <script type="text/javascript" scr="<?php echo base_url()?>js/jquery.validate.min.js"></script>
    <title>Questions</title>
</head>
<body>
    <div class="frm"><?php $a=array("id"=>"myForm","name"=>"myForm");
echo form_open('site/search',$a); ?>
        <div>
            <?php echo form_label('Question:','question'); ?>
            <?php echo form_input('question', set_value('question', @$_GET['question']), 'id="question"', 'name="question"'); ?>
        </div>
        <div>
            <?php echo form_label('Category:','category'); ?>
            <?php echo form_dropdown('category', $category_options, set_value('category', @$_GET['category']), 'id="category"', 'name="category"'); ?>
        </div>
        <div>
            <?php echo form_label('Score:','score'); ?>
        <?php echo form_dropdown('score_comparison', array('gt' => '>', 'gte' =>'>=' , 'eq' => '=', 'lt' => '<', 'lte' => '<='), set_value('score_comparison', @$_GET['score_comparison']), 'id="score_comparison"', 'name="score_comparison"'); ?>
        <?php echo form_input('score', set_value('score', @$_GET['score']), 'id="score"', 'name="score"'; ?>
         </div>
         <div>
             <?php echo form_submit('action','');?>
         </div>
         <?php echo form_close();?>
    </div>
   <script type="text/javascript">
    $(document).ready(function () {
        $("#myForm").validate({
            rules: {
                question: {
                    required: true
                }
            },
            messages: { 
                question:{
                    required: "Please enter some text" 
                }
            }
        });
    });
</script>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • doubi9531 2016-01-13 20:49
    关注

    First off all, replace you <?php echo base_url()?> with just /. You can use relative path for resources from your site. Path should be like this: scr="/js/jquery-1.12.0.js" for all you scripts.

    For second replace your string $().ready(function () { with $(function () {

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧