我已经在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
发布评论