script.js file not linking to index.html
I am using sublime and trying to practice building a site. Here’s the HTML and JS that I am trying to connect, please tell me what I’m doing wrong because the alert is not coming up when I open index.html in Chrome.
It’s written in another file called «script.js» and I want to link to it like the linking to my css file
4 Answers 4
You need to put javascript code in tags:
And since you are using ready method of jQuery, make sure it is included first before using it with:
To use this you must include both jQuery and surround the javaScript with tags. If, however, you want to include everything in script.js, it might not be the best thing to write everything in tags, just write everything in «script.js»
This should do the trick. (also remember that if you use this kind of import, you have to place script.js in the same folder. If you placed it in a different folder such as ‘js’ you have to do a import like:
download here http://jquery.com/download/ and add in head section
Howhever if you want include jquery in other file and include only this file, you can add the line code above in a file html and in the head section add this line code that write te content in output
All content of file.html will be written.
for css except the ; character is all ok. but for js you can use this attributes: src for the logical path of your file js and type that identifies the type of file. if you want add another file js, put another tag script like the other with this example script is saved in the root of your application
This is very simple stuffs which new people to JavaScript may miss it, there are two ways to do it:
1) in Simple structure of HTML page, everything in the page is counted as HTML unless they are in or tags, so in your case you need to do it inside tag like this:
2) You may want it in separate file, like the link you did it to script.js , in this case, just simply put the js file in script.js without any tag.
Node.js. Why is the page cannot load css and javascript file?
i have created a node.js server. When i entered the localhost using port 3000, it displayed text only without css or javascript. I have tried several solutions that have worked on others. but they didn’t worked for me. Node JS keep getting Failed to load resource error message static files with express.js Can not get CSS file my file order is like this
server.js index.html public css style.css
var express = require('express'); var app = express(); app.get('/', function(req, res) < res.sendFile(__dirname + '/index.html');>); app.use(express.static(__dirname + 'public')); app.listen(3000);
GET http://localhost:3000/ [HTTP/1.1 304 Not Modified 11ms] GET http://localhost:3000/public/css/demo.css [HTTP/1.1 404 Not Found 10ms] GET http://localhost:3000/public/css/themes/popclip.css [HTTP/1.1 404 Not Found 10ms] GET http://localhost:3000/public/css/reveal.min.css [HTTP/1.1 404 Not Found 19ms] GET http://localhost:3000/public/css/theme/default.css [HTTP/1.1 404 Not Found 12ms] GET http://localhost:3000/public/css/jquery.dropdown.css [HTTP/1.1 404 Not Found 11ms] GET http://localhost:3000/node_modules/socket.io/node_modules/socket.io-client/socket.io.js [HTTP/1.1 404 Not Found 10ms] GET http://localhost:3000/public/js/jquery.min.js [HTTP/1.1 404 Not Found 29ms] GET http://localhost:3000/public/js/jquery.popline.js [HTTP/1.1 404 Not Found 28ms] GET http://localhost:3000/public/js/plugins/jquery.popline.link.js [HTTP/1.1 404 Not Found 28ms]
Почему HTML не видит js функцию?
Добавил в html форму и кнопку, нажимая на которую должна вызываться функция из скрипта.
Если в этом скрипте пишу только функцию, то все работает, но если туда добавить импорты, то уже пишет, что функция нигде не используется и соответственно скрипт не работает.
Send message
/*import from "./Parameters"; import from "./client";*/ function get_input_data()
Простой 1 комментарий
А что в консоли? Её смотрите.
Скорее всего, js файл чуть больше и там где-то ошибка, и до места объявления функции он просто не доходит. Но это пальцем в небо. Ведь также возможно, что вы банально ошиблись в пути файла. И куча других причин. Это всё можно узнать через devtools (кнопка F12 в браузере).
Если не ошибаюсь, onsubmit работает только со скриптами, прописанными в том же html-файле, внутри тега script. С внешними файлами он не работает. В любом случае, сабмитить из html — так себе практика. Если вы все равно пишете js во внешних файлах, то и сабмит там же делайте. А для доступа к конкретным значениям формы пользуйтесь атрибутами name:
const form = document.querySelector('#form') function submitForm(event) < event.preventDefault() console.log(event.target.textField.value) >form.addEventListener('submit', submitForm)
Браузер не видит js-скрипты
Здравствуйте!
Два дня назад, по непонятной мне причины, перестали работать js-скрипты. Ни кнопки, ни trackbar, jCarousel ни чего не работает, только в IE работает, в остальных браузерах нет. Почему так? Какие могут быть причины?
В консоль показывает ошибку.
браузер не видит PHP скрипты которые я пишу
почему то не работают РНР скрипты некоторые. вот например пишу строку в которую текст вводить и.
Скрипты, встраиваемые в браузер
С недавнего времени на всех сайтах, открываемых в браузере в код вставляются многочисленные.
Браузер не обновляет скрипты
Пишу на sublime text 3, браузер google chrome, использую open server. Пишу скрипт и он его не.
Браузер не отображает скрипты
По чему в браузере ничего не отображается если я открываю и закрываю php скрипт этими тегами.
Сообщение от Balanaar
Дак если пути к скриптам не верны, почему тогда в IE все работает.
Скрипты у меня находятся в папке js, путь к ним прописываю так:
1 2 3 4 5 6 7 8 9 10 11 12 13
script type="text/javascript" src="/js/jquery-1.8.2.min.js">script> script type="text/javascript" src="/js/jcarousellite_1.1.js">script> script type="text/javascript" src="/js/jquery.cookie.js">script> script type="text/javascript" src=/trackbar/jquery.trackbar.js">
Сообщение от Balanaar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
script type="text/javascript" src="js/jquery-1.8.2.min.js">/script> script type="text/javascript" src="js/jcarousellite_1.1.js">/script> script type="text/javascript" src="js/jquery.cookie.js">/script> script type="text/javascript" src="trackbar/jquery.trackbar.js">/script> script type="text/javascript" src="trackbar/trackbar.js">/script> script type="text/javascript" src="js/jquery.form.js">/script> script type="text/javascript" src="js/jquery.validate-1.15.0.min.js">/script> script type="text/livescript" src="js/additional-methods.js">/script> script type="text/javascript" src="js/jquery.maskedinput.min.js">/script> script type="text/javascript" src="js/moment.js">/script> script type="text/javascript" src="js/shop-validate.js">/script> script type="text/javascript" src="js/jquery.textchange.js">/script> script type="text/javascript" src="js/jTabs.js">/script> script type="text/javascript" src="fancybox/jquery.fancybox.3.1.25.min.js">/script> script type="text/javascript" src="fancybox/jquery.mousewheel-3.0.6.pack.js">/script> script type="text/javascript" src="fancybox/jquery.fancybox.js?v=2.1.5">/script> script type="text/javascript" src="fancybox/helpers/jquery.fancybox-buttons.js?v=1.0.5">/script> script type="text/javascript" src="fancybox/helpers/jquery.fancybox-thumbs.js?v=1.0.7">/script> script type="text/javascript" src="fancybox/helpers/jquery.fancybox-media.js?v=1.0.6">/script> script type="text/javascript" src="js/shop-script.js">/script>
Сообщение от Balanaar
Нет, не пробовал. сейчас попробую почистить. Хотя, я сброс настроек делал в Google Chrome.
Добавлено через 23 минуты
Все, кеш очистил, но, результат == 0.
DDim1000, чет у вас пути скачут — то кавычки не правильно расставлены, то слэш с начала пути пропал. Вы ручками их сюда переписываете?
Сообщение от j2FunOnly
DDim1000, чет у вас пути скачут — то кавычки не правильно расставлены, то слэш с начала пути пропал. Вы ручками их сюда переписываете?
j2FunOnly, последнии пути верны! Если впереди ставить слэш, то в браузере получается двойной слэш перед каталогом js.