עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

קוד javascript בסיסי, לא עובד לי !

Featured Replies

פורסם

שלום,

רציתי להעלות דף המכיל תמונה שכאשר לוחצים עליה היא משתנה לתמונה אחרת. עשיתי זאת ע"י סקריפט javascript ולא הצלחתי. ניסיתי לפשט את הקוד כך שלחיצה על תמונה תעלה תו acii כלשהו וגם בכך נכשלתי. הרי הקוד:


<head>
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function ChangeImage(param)
{
document.write(param);

if(param=="file:///D:/js/examples/tanzania/gallery/dar2.jpg")
{
document.write('1');
/*document.getElementById("myID").src="D:/js/examples/tanzania/gallery/dar3.jpg";*/
}
else
(
document.write('1');
)
}
-->
</script>
</head>

<body>
<img id="myID" src="tanzania/gallery/dar2.jpg" onclick="ChangeImage(document.getElementById('myID').src)"/>
</body>
</html>

הדף במקורו מראה תמונה. כשאני מקליק עליה אני מצפה לראות לפחות '1' או '2'. מילא שתמונה אחרת אינני מצליח להעלות אבל תו אסקי פשוט ?!

מישהו יוכל בבקשה להצביע על טעותי ?

תודה !

פורסם

אתה לא יכול לגשת ישירות ל-attribute של אלמנט ב-DOM כאילו זה משתנה של אובייקט רגיל. אין דבר כזה:

document.getElementById('myID').src

כדי לגשת ל-src אתה צריך לעבור דרך מערך שמחזיק את כל ה-attributes של האובייקט. דוגמה:

var imageattributes=document.getElementById("myID").attributes

imageattributes[0].name //name of the first attribute of "myID"

imageattributes[0].value //value of the first attribute of "myID"

imageattributes.getNamedItem("src").value //value of the "src" property of "myID"

לפרוט מלא על אובייקטים ב-DOM (אובייקטים של הדפדפן) תסתכל פה:

http://www.javascriptkit.com/domref/elementproperties.shtml

מומלץ מאוד ללמוד לעבוד עם firebug וה-debugger שלו, יחסוך לך הרבה שעות של תיסכול.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.