dongpang2029 2016-01-13 09: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 12: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 爱快路由器端口更改错误导致无法访问
  • ¥20 安装catkin时遇到了如下问题请问该如何解决呢
  • ¥15 VAE模型如何输出结果
  • ¥15 编译python程序为pyd文件报错:{"source code string cannot contain null bytes"
  • ¥20 关于#r语言#的问题:广义加行模型拟合曲线后如何求拐点
  • ¥15 fluent设置了自动保存后,会有几个时间点不保存
  • ¥20 激光照射到四象线探测器,通过液晶屏显示X、Y值
  • ¥50 数据库开发问题求解答
  • ¥15 安装anaconda时报错
  • ¥15 小程序有个导出到插件方式,我是在分包下引入的插件,这个export的路径对吗,我看官方文档上写的是相对路径
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部