Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

Inline vs external javascript

Автор: kudvenkat

Загружено: 2014-11-02

Просмотров: 147130

Описание:

Link for all dot net and sql server video tutorial playlists
   / kudvenkat  

Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspo...

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

In this video we will discuss
1. Different places where JavaScript can be present
2. Advantages of external JavaScript over inline JavaScript

JavaScript can be stored either inline on the page or in an external .js file. Let's look at an example of both the approaches.

Inline JavaScript example : In this example, IsEven() JavaScript function is present inline on the page.
[html]
[head]
[script type="text/javascript"]
function IsEven()
{
var number = document.getElementById("TextBox1").value;
if (number % 2 == 0)
{
alert(number + " is even number");
}
else
{
alert(number + " is odd number");
}
}
[/script]
[/head]
[body]
[form id="form1" runat="server"]
Number :
[asp:TextBox ID="TextBox1" runat="server"][/asp:TextBox]
[input type="button" value="Check Number" onclick="IsEven()" /]
[/form]
[/body]
[/html]

External JavaScript example : Steps to store JavaScript in an external .js file
1. In Visual Studio, right click on the project name in Solution Explorer and select add select Add =] New Item
2. From the "Add New Item" dialog box select "JScript File". Name the file "ExternalJavaScript.js" and click Add.
3. Copy and paste the following JavaScript function in the "ExternalJavaScript.js" file

function IsEven()
{
var number = document.getElementById("TextBox1").value;
if (number % 2 == 0)
{
alert(number + " is even number");
}
else
{
alert(number + " is odd number");
}
}

4. On your webform in the head section include a reference to the external JavaScript file using script element as shown below
[script type="text/javascript" src="ExternalJavaScript.js"][/script]

5. At this point the HTML on your webform should be as shown below.
[html]
[head]
[script type="text/javascript" src="ExternalJavaScript.js"][/script]
[/head]
[body]
[form id="form1" runat="server"]
Number :
[asp:TextBox ID="TextBox1" runat="server"][/asp:TextBox]
[input type="button" value="Check Number" onclick="IsEven()" /]
[/form]
[/body]
[/html]

Advantages of external JavaScript over inline JavaScript : Here are some of the general advantages of external JavaScript over inline JavaScript

Maintainability : JavaScript in external files can be referenced on multiple pages without having to duplicate the code inline on every page. If something has to change, you only have one place to change. So external JavaScript code can be reused and maintenance will be much easier.

Separation of Concerns : Storing JavaScript in a separate external .js file adheres to Separation of concerns design principle. In general it is a good practice to separate HTML, CSS and JavaScript as it makes it easier working with them. Also allows multiple developers to work simultaneously.

Performance : An external JavaScript file can be cached by the browser, where as an inline JavaScript on the page is loaded every time the page loads.

Inline vs external javascript

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

Где следует разместить тег script в HTML?

Где следует разместить тег script в HTML?

JavaScript Let vs Var vs Constant | Mosh

JavaScript Let vs Var vs Constant | Mosh

Python  - Полный Курс по Python [15 ЧАСОВ]

Python - Полный Курс по Python [15 ЧАСОВ]

Что со здоровьем Кадырова и его сына? Самый полный разбор

Что со здоровьем Кадырова и его сына? Самый полный разбор

Декораторы Python — наглядное объяснение

Декораторы Python — наглядное объяснение

Events in JavaScript

Events in JavaScript

JavaScript Tutorial

JavaScript Tutorial

Loops in JavaScript

Loops in JavaScript

Errors in JavaScript | JavaScript Tutorial | Mr. Subba Raju

Errors in JavaScript | JavaScript Tutorial | Mr. Subba Raju

Complete JavaScript Course | 2025

Complete JavaScript Course | 2025

Python if __name__ == '__main__': наглядное объяснение

Python if __name__ == '__main__': наглядное объяснение

Я в опасности

Я в опасности

Учим HTML и CSS за 7 часов! Уроки по созданию сайтов Полный курс HTML и CSS с нуля до профессионала

Учим HTML и CSS за 7 часов! Уроки по созданию сайтов Полный курс HTML и CSS с нуля до профессионала

Межсайтовый скриптинг (XSS) объяснен и продемонстрирован профессиональным хакером!

Межсайтовый скриптинг (XSS) объяснен и продемонстрирован профессиональным хакером!

Converting strings to numbers in JavaScript

Converting strings to numbers in JavaScript

JavaScript Form Validation

JavaScript Form Validation

Event bubbling in JavaScript

Event bubbling in JavaScript

JavaScript array mutators

JavaScript array mutators

Arrays in javascript

Arrays in javascript

JavaScript substring example

JavaScript substring example

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com