0

How can I add a jquery script in mi view in yii 2.0 ? I was searching and i found this command

$this->registerJs('$(function ()
    {
        $("#wizard").steps({
            headerTag: "h2",
            bodyTag: "section",
            transitionEffect: "slideLeft"
        });

        $("#wizard-vertical").steps({
            headerTag: "h2",
            bodyTag: "section",
            transitionEffect: "slideLeft",
            stepsOrientation: "vertical"
        });
    });', 3);

and the output is this, a javascript

    <script type="text/javascript">$(function ()
    {
        $("#wizard").steps({
            headerTag: "h2",
            bodyTag: "section",
            transitionEffect: "slideLeft"
        });

        $("#wizard-vertical").steps({
            headerTag: "h2",
            bodyTag: "section",
            transitionEffect: "slideLeft",
            stepsOrientation: "vertical"
        });
    });</script>

the problem is I need to use it as a JQuery Script like this

<script>
        $(function ()
        {
            $("#wizard").steps({
                headerTag: "h2",
                bodyTag: "section",
                transitionEffect: "slideLeft"
            });

            $("#wizard-vertical").steps({
                headerTag: "h2",
                bodyTag: "section",
                transitionEffect: "slideLeft",
                stepsOrientation: "vertical"
            });
        });
    </script>   

But I don't know how to print a JQuery Script, somebody knows?

3
  • 2
    The 2 are pretty much equivalent. What seems to be the problem? Commented Dec 27, 2014 at 16:49
  • the question makes no sense.... Commented Dec 28, 2014 at 11:42
  • jQuery is JS, so its the correct syntax. If its not working, make sure the jQuery-file is loaded and that the JS is executed after the jQuery-load. Commented Dec 28, 2014 at 12:41

1 Answer 1

3

you may use this....

update or include jquery code in app\assets\AppAsset.php file

class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',
    ];
    public $js = [    // add required js file....
    'js/jquery.min',
    'js/jquery-scrollToTop',

    ];
    public $jsOptions = [
    'position' => \yii\web\View::POS_HEAD  // include js at <head> tag....
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
    ];
}

so, i hope this ans help you.........:)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.