此内容来自第三方平台 (Dailymotion)。如果此视频侵犯了您的版权,请使用 立即删除 工具。
Disadvantages of JavaScript
描述
In this video we will discuss the disadvantages or downsides of using JavaScript.
There are two main disadvantages of JavaScript.
Security : JavaScript runs on the client machine. So a malicious user may use Javascript to do a variety of things like tracking your browsing history, stealing passwords etc. This is one of the main reasons why people disable JavaScript.
Browser Compatibility : Not all browsers treat the same piece of JavaScript in the same manner. This means the functionality and the user interface may vary from browser to browser. That is why cross-browser testing is very important. However, with JavaScript libraries like jQuery Browser Compatibility is no longer a major issue.
JavaScript Browser Compatibility Examples
Example 1 : innerText property is supported in IE & Chrome, but not in Firefox. This means the ValidatForm() JavaScript function that we worked with in Part 1, will only work in IE & Chrome but not in Firefox.
function ValidatForm()
{
var ret = true;
if (document.getElementById("txtFirstName").value == "")
{
document.getElementById("lblFirstName").innerText = "First Name is required";
ret = false;
}
else
{
document.getElementById("lblFirstName").innerText = "";
}
if (document.getElementById("txtLastName").value == "")
{
document.getElementById("lblLastName").innerText = "Last Name is required";
ret = false;
}
else
{
document.getElementById("lblLastName").innerText = "";
}
if (document.getElementById("txtEmail").value == "")
{
document.getElementById("lblEmail").innerText = "Email is required";
ret = false;
}
else
{
document.getElementById("lblEmail").innerText = "";
}
return ret;
}
For the above JavaScript function to work in all the browsers that is in IE, Chrome & Firefox, replace innerText property with textContent as shown below.
function ValidatForm()
{
var ret = true;
if (document.getElementById("txtFirstName").value == "")
{
document.getElementById("lblFirstName").textContent = "First Name is required";
ret = false;
}
else
{
document.getElementById("lblFirstName").textContent = "";
}
if (document.getElementById("txtLastName").value == "")
{
document.getElementById("lblLastName").textContent = "Last Name is required";
ret = false;
}
else
{
document.getElementById("lblLastName").textContent = "";
}
if (document.getElementById("txtEmail").value == "")
{
document.getElementById("lblEmail").textContent = "Email is required";
ret = false;
}
else
{
document.getElementById("lblEmail").textContent = "";
}
return ret;
}
There are two main disadvantages of JavaScript.
Security : JavaScript runs on the client machine. So a malicious user may use Javascript to do a variety of things like tracking your browsing history, stealing passwords etc. This is one of the main reasons why people disable JavaScript.
Browser Compatibility : Not all browsers treat the same piece of JavaScript in the same manner. This means the functionality and the user interface may vary from browser to browser. That is why cross-browser testing is very important. However, with JavaScript libraries like jQuery Browser Compatibility is no longer a major issue.
JavaScript Browser Compatibility Examples
Example 1 : innerText property is supported in IE & Chrome, but not in Firefox. This means the ValidatForm() JavaScript function that we worked with in Part 1, will only work in IE & Chrome but not in Firefox.
function ValidatForm()
{
var ret = true;
if (document.getElementById("txtFirstName").value == "")
{
document.getElementById("lblFirstName").innerText = "First Name is required";
ret = false;
}
else
{
document.getElementById("lblFirstName").innerText = "";
}
if (document.getElementById("txtLastName").value == "")
{
document.getElementById("lblLastName").innerText = "Last Name is required";
ret = false;
}
else
{
document.getElementById("lblLastName").innerText = "";
}
if (document.getElementById("txtEmail").value == "")
{
document.getElementById("lblEmail").innerText = "Email is required";
ret = false;
}
else
{
document.getElementById("lblEmail").innerText = "";
}
return ret;
}
For the above JavaScript function to work in all the browsers that is in IE, Chrome & Firefox, replace innerText property with textContent as shown below.
function ValidatForm()
{
var ret = true;
if (document.getElementById("txtFirstName").value == "")
{
document.getElementById("lblFirstName").textContent = "First Name is required";
ret = false;
}
else
{
document.getElementById("lblFirstName").textContent = "";
}
if (document.getElementById("txtLastName").value == "")
{
document.getElementById("lblLastName").textContent = "Last Name is required";
ret = false;
}
else
{
document.getElementById("lblLastName").textContent = "";
}
if (document.getElementById("txtEmail").value == "")
{
document.getElementById("lblEmail").textContent = "Email is required";
ret = false;
}
else
{
document.getElementById("lblEmail").textContent = "";
}
return ret;
}
相关视频
Advantage & Disadvantages of external fertilization | Advantage & Disadvantages of external fertilization in Hindi | Advantage & Disadvantages of external fertilization biology #cityclasses
cityclasses
disadvantages of mountain dew _ disadvantages of cold drinks
Daily Fun Videos
Advantage & Disadvantages of internal fertilization | Advantage & Disadvantages of internal fertilization in Hindi #cityclasses
cityclasses
TAKE ADVANTAGE of DISADVANTAGES _Intense Motivational Video_#disadvantage #inspiration #life
spiritualityunited
Direct Cremation Disadvantages
jenylarry
Disadvantages of cell phone
Emran Khan Bwn