Accordion not working

I am trying to use an accordion. The function I use is

$(function() { $("#accordion").accordion({ collapsible: true, heightStyle: "content" }); }); 

The function works correctly, but only if I add the libraries on the same page where I use the accordion.

 <script src="http://code.jquery.com/jquery-1.8.2.js"></script> <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script> 

when I load the css file and gave the path in view.yml. But if I do the same for the js file (download and give the path in view.yml), it does not seem to work. I want to reuse them on many pages, so I do not want to include a web path on each page.

Secondly, if I give the path on the page, the boot block doesn't seem to work properly, a collision or something like that happens. Give me a solution for this. Avoid specifying a path on all pages. Thanks!

+4
source share
1 answer

You will need a general view or layout containing links to the public script files used on all pages. Then you can simply include the script tag in this place.

For example, in ASP.NET-MVC, if you are using razor views, the file '_Layout.cshtml' should already be specified in your _ViewStart.cshtml file. If not, you can simply add a link to the general view in any file, for example:

 @{Layout = "~/Views/Shared/_Layout.cshtml";} 

Then just include the necessary script (s) in the _Layout file.

You can do something similar in php by simply adding an include statement to each view, for example:

 < ? php include 'header.php'; ?> 

Then just reference the jquery copy or pull it from the CDN in the header.php file.

For more information, try the following links:
ASP.NET-MVC: http://www.w3schools.com/aspnet/mvc_layout.asp

PHP: http://www.w3schools.com/php/php_includes.asp

0
source

Source: https://habr.com/ru/post/1440276/


All Articles