• خانه
  • دوره گواهینامه تخصصی IT

دوره گواهینامه تخصصی IT

دوره گواهینامه تخصصی IT

خروجی

امکان نمایش جاوا اسکریپت

JavaScript می تواند داده ها را به روش های مختلف “نمایش” دهد:

  • Writing into an HTML element, using innerHTML.
  • Writing into the HTML output using document.write().
  • Writing into an alert box, using window.alert().
  • Writing into the browser console, using console.log().

با استفاده از innerHTML
برای دسترسی به یک عنصر HTML ، JavaScript می تواند از روش document.getElementById (id) استفاده کند.

ویژگی id عنصر HTML را تعریف می کند. خاصیت innerHTML محتوای HTML را تعریف می کند:

مثال:
<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My First Paragraph</p>

<p id=”demo”></p>

<script>
document.getElementById(“demo”).innerHTML = 5 + 6;
</script>

</body>
</html>
تغییر ویژگی داخلیHTML یک عنصر HTML یک روش معمول برای نمایش داده ها در HTML است.

Using document.write()
برای اهداف آزمایش ، استفاده از document.write () راحت است:

مثال:
<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<script>
document.write(5 + 6);
</script>

</body>
</html>
Using document.write() after an HTML document is loaded, will delete all existing HTML:

Example
<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<button type="button" onclick="document.write(5 + 6)">Try it</button>

</body>
</html>
The document.write() method should only be used for testing.

Using window.alert()
You can use an alert box to display data:

Example:
<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<script>
window.alert(5 + 6);
</script>

</body>
</html>
Using console.log()
برای اهداف اشکال زدایی ، می توانید برای نمایش داده ها با روش console.log () در مرورگر تماس بگیرید.

در بخش بعدی درباره اشکال زدایی بیشتر خواهید آموخت.

Example:
<!DOCTYPE html>
<html>
<body>

<script>
console.log(5 + 6);
</script>

</body>
</html>
JavaScript Print
JavaScript does not have any print object or print methods.

در بخش بعدی درباره اشکال زدایی بیشتر خواهید آموخت.

تنها استثنا این است که شما می توانید با استفاده از روش window.print () در مرورگر محتوای پنجره فعلی را چاپ کنید.