Jquery选择的插件在一个页面中工作,但在另一个页面中不起作用

时间:2015-03-28 10:10:53

标签: jquery model-view-controller jquery-plugins jquery-chosen

您好我以前在其他项目中使用过选择并且我没有遇到任何问题但现在在我当前的项目中我不能让它在特定页面上工作,尽管它适用于另一个页面。

Firebug gives me the error:
 SyntaxError: expected expression, got '<'
 '!doctype html'
 chosen.jquery.js (row 1)

 SyntaxError: expected expression, got '<'

'!doctype html'

 prism.js (row 1)

 TypeError: $(...).chosen is not a function

$(selector).chosen(config[selector]);

我开发的网站使用的是MVC框架,显示/加载脚本的视图,不起作用的视图,看起来像这样(编辑问题):

&#13;
&#13;
<h1><?=$title?></h1>
<form method='post'>
    <fieldset>
        <input type='hidden' name='id' value='<?=$id?>' required/>
        <input id='textField' type='text' name='titel' placeholder='Titel' value='<?=$titel?>' tabindex='1' required/>
        <textarea id='askQuestion' name='text' placeholder='Fråga' tabindex='2' required/><?=$text?></textarea>
        <select name='tags[]' data-placeholder='Välj taggar, minst 1 - högst 5' class='chosen-select-deselect' tabindex='2'  multiple >
            <option value=''></option>
            <?php
                foreach($tags as $tag){
                $selected="";
                foreach($selectedTags as $selectedTag){
                    if($tag->name == $selectedTag){
                        $selected = "selected";
                    }
                }
                    echo "<option value='$tag->id' $selected >{$tag->name}</option>";
                }
             ?>

       </select>
        <input class='newTags' type='text' name='newTags' placeholder='Ange ny tagg/taggar "taggnamn, taggnamn"'/>
    <input type='submit' name='editQuestion' value='Uppdatera'>
    </fieldset>

<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js' type='text/javascript'></script>
    <script src='js/chosen_v1.4.1/chosen.jquery.js' type='text/javascript'></script>
    <script src='js/chosen_v1.4.1/docsupport/prism.js' type='text/javascript' charset='utf-8'></script>
    <script type='text/javascript'>
    var config = {
      '.chosen-select'           : {},
      '.chosen-select-deselect'  : {allow_single_deselect:true, width:'100%', max_selected_options:5},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
      '.chosen-select-width'     : {width:'95%'}
    }

    for (var selector in config) {
      $(selector).chosen(config[selector]);
    }
    </script>
</form>
&#13;
&#13;
&#13;

工作的观点(提问):

&#13;
&#13;
<h1><?=$title?></h1>
<form method='post'>
    <fieldset>
        <input id='textField' type='text' name='titel' placeholder='Titel' tabindex='1' title='Ange en titel på frågan' required/>
        <textarea id='askQuestion' name='text' placeholder='Fråga' tabindex='2' title='Ange frågan' required/></textarea>
        <select name='tags[]' data-placeholder='Välj taggar, minst 1 - högst 5' class='chosen-select-deselect' tabindex='3' multiple >
            <option value=''></option>
            <?php foreach($tags as $tag) : ?>
                <option value='<?=$tag->id?>'><?=$tag->name?></option>
            <?php endforeach; ?>
        </select>
        <input class='newTags' type='text' name='newTags' placeholder='Ange ny tagg/taggar "taggnamn, taggnamn"'/>
    <input type='submit' name='createQuestion' value='Skapa'>
    </fieldset>


    <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js' type='text/javascript'></script>
    <script src='js/chosen_v1.4.1/chosen.jquery.js' type='text/javascript'></script>
    <script src='js/chosen_v1.4.1/docsupport/prism.js' type='text/javascript' charset='utf-8'></script>
    <script type='text/javascript'>
    var config = {
      '.chosen-select'           : {},
      '.chosen-select-deselect'  : {allow_single_deselect:true, width:'100%', max_selected_options:5},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
      '.chosen-select-width'     : {width:'95%'}
    }
    for (var selector in config) {
      $(selector).chosen(config[selector]);
    }
    </script>
</form>
&#13;
&#13;
&#13;

两个视图在显示时都有相同的文件路径,我唯一能想到的区别是两个视图/页面是不起作用的(edit-question)有一个不同的URL,webroot / questions / edit-question / 3/3/8,而另一个,提问,有webroot / ask-question。此外,编辑问题是用值填充html输入元素。

我对jquery / javascript不是很精通,所以任何帮助都很有用!

/ PH

0 个答案:

没有答案