JQuery表单验证对我不起作用(JQuery form validation does not work for me)

编程入门 行业动态 更新时间:2024-10-25 23:38:21
JQuery表单验证对我不起作用(JQuery form validation does not work for me)

我已经在http://jsfiddle.net/gLpHY/92/中测试了这段代码,在那里运行正常,但是当我在计算机上运行它时它不起作用。 (我只使用html和jquery测试了这个代码的两个版本,下次我用它们用php时,它们都不适用于我。)

<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>

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>

最满意答案

首先,只需用/替换<?php echo base_url()?> 。 您可以使用站点中资源的相对路径。 路径应该是这样的:所有脚本的scr="/js/jquery-1.12.0.js" 。

第二次替换你的字符串$().ready(function () { with $(function () {

希望这可以帮助。

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.

更多推荐

php,echo,电脑培训,计算机培训,IT培训"/> <meta name="description" co

本文发布于:2023-07-22 19:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222772.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对我   表单   不起作用   JQuery   validation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!