עבור לתוכן
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.

בעיה ב JS למה הקוד לא עובד?

Featured Replies

פורסם


<html>
<head>
<script language="javascript">
function func() {
a = window.document.form.one;

if (a.checked == false) {
document.bgcolor='red';
}
else {
document.bgcolor='black';
}
}
</script>
</head>
<body>
<form name="form">
<input type="checkbox" name="one" onClick="func();">
</form>
</body>
</html>

למה זה לא עובד?

פורסם

JAVASCRIPT שפה מאוד רגישה ל CASE SENSETIVE.. תהפוך את ה document.bgcolor ל document.bgColor

חיפוש של 2 שניות בגוגל הראה את ה SCRIPT הזה, תנסה להתאים אותו לצרכים שלך:

http://www.javascripter.net/faq/backgrou.htm

http://www.google.com/search?q=javascript+document+background&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8&client=firefox&rls=org.mozilla:en-US:unofficial

פורסם
  • מחבר

לא עובד

פורסם

עובד מעולה ב FIREFOX, ב IE יש איזה חסימה של ה SP2 משום מה... כנראה שצריך לעשות את זה בדרך אחרת.

פורסם

זה עובד גם בSP2.

פורסם

אצלי הייתי צריך להגיד לו ALLOW ACTIVE CONTENT או משהו כזה, כדי שזה יפעל..

פורסם

עדכון.. תנסה אולי להוריד את ה window מה window.document אולי זה מה שיוצר את הבעיה ב IE XP SP2

פורסם

כמה הערות לפני זה:

1. הקוד שלך לא תקני, חשוב שתעקוב אחרי החוקים של w3c לגבי xhtml וכן DOM.

2. אין צורך לפתוח טופס, כי אתה לא שולח מידע.

3. יש לסגור כל תג, גם אם הוא אונרי (דוגמה: </ br>)

הנה הקוד שלי:


<script language="JavaScript" type="text/JavaScript">
function bg_color_changer(n) {
if (n.checked==true) document.bgColor='#FF0000';
else document.bgColor='#000000';
}
</script>

והפקד במסמך:

<input type="checkbox" name="color" id="color" value="1" onclick="bg_color_changer(this);" />

זה יעבוד לך בכל דפדפן...(:

(שים לב שהמאפיין bgColor נדחה ע"י w3c כמאפיין סטנדרטי של DOM, אבל הוא בכל זאת נתמך על ידי כל הדפדנים. השיטה שבה על פי w3c לשנות מאפיין רקע הוא ע"י css, כלומר לספק לתג body מזהה, כמו <"body id="main> ואז בקוד להשתמש באלמנט הבא:

;'GetElementById('main').style.background-color='red

אני לא בדקתי את זה ויכול להיות שיש לי פה שגיאת תחביר כלשהי, אבל זו השיטה העתידית על פי התקינה ומודל האובייקטים DOM)

ארכיון

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

דיונים חדשים

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.