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

פורסם

הי, יש לי את אותו קוד בידיוק שמשנה צבעים לפי 4 מצבים, מה שאני עושה בנתיים זה להשתמש בSWITCH אבל זה ניראה לי לא יעיל. האם יש דרך שאני יכול לקחת סטרינג שמאוחסן במשתמש ולהוציא ממנו את שם המשתמש שממנו אני רוצה למשוך מידע? לדוגמא:


var i = 'name';
var name = ['123', '456'];
wanted result , something like => i[1] = 456

תודה

פורסם

פרט והסבר. לא הצלחתי להבין מה בדיוק אתה מנסה לעשות.

יעזור גם לראות את הקוד הנוכחי שלך (ה switch שדיברת עליו) כדי להבין את דרך השימוש והתוצאה הסופית שאתה מנסה להשיג.

פורסם

להעביר בסטרינג שם משתמש אפשרי אם משתמשים ב-eval אבל זה מאוד לא מומלץ. אני לא בטוח שהבנתי מה אתה מנסה לעשות, אולי משהו כזה יעזור לך:

var options = {
name1: [123,456],
name2: [789,101]
};
var i = "name1";
return options[i][1];

פורסם
  • מחבר

השיטה שלך ניראה סבבה תודה, אני רק רוצה באמת להראות לכם את הקוד אולי למישהו יש שיטה יותר נוחה או סתם עוד שיטה (בכל מיקרה בקשר לשינויים בCSS, אני יודע שיש דרך להכניס את כל השינויים לפקודה אחת אבל יש שם איזה באג לא ברור שגורם לזה לא לשנות כלום אם אני עושה את זה ולכן זה מפוצל למלא שורות)



var dawn = ['#fcbd8d', '#a3a7cc'];
var noon = ['#B7CFEB', '#607EA3'];
var dusk = ['#805d48', '#718db0'];
var night = ['#747EAD', '#323752'];

switch (headerBackground.day_part) {
case 'dawn':
console.log('colouring dawn');
$('#header-background').css('background-color', dawn[1]);
$('#header-background').css('background-image', ' -webkit-linear-gradient(bottom,' + dawn[0] + ' 0%,' + dawn[1] + ' 100%)');
$('#header-background').css('background-image', '-moz-linear-gradient(bottom,' + dawn[0] + ' 0%,' + dawn[1] + ' 100%)');
$('#header-background').css('background-image', 'linear-gradient(bottom,' + dawn[0] + ' 0%,' + dawn[1] + ' 100%)');
$('#header-background').css('background-image', '-o-linear-gradient(bottom,' + dawn[0] + ' 0%,' + dawn[1] + ' 100%)');
$('#header-background').css('background-image', 'progid:DXImageTransform.Microsoft.gradient(startColorstr=' + dawn[0] + ', endColorstr=' + dawn[1] + ', gradientType=1)');

$('#outside_text_logo').css('color', '#bc9f69')
$('#outside_text_logo .faqLink').css({
'color' : '#d6b474',
'border-color' : '#d6b474'
});
$('#outside_text_logo .faqLink').hover(function(){
$(this).css({
'color' : '#ead2a6',
'border-color' : '#ead2a6'
});
}, function(){
$(this).css({
'color' : '#d6b474',
'border-color' : '#d6b474'
});
});
break;
case 'noon':
$('#header-background').css('background-color', noon[0]);
$('#header-background').css('background-image', ' -webkit-linear-gradient(bottom,' + noon[0] + ' 0%,' + noon[1] + ' 100%)');
..........






פורסם

יכולת לעשות את זה פשוט ככה:

var colors
switch (headerBackground.day_part) {
case 'dawn':
colors=['#fcbd8d', '#a3a7cc'];
break;
case 'noon':
colors=['#B7CFEB', '#607EA3'];
break;
case 'dusk':
colors=['#805d48', '#718db0'];
break;
case 'night':
colors=['#747EAD', '#323752'];
break;
}
...
whateverYouWant = colors[0]; whateverYouWant = colors[1];

ואם רוצים להשתמש במה ש etal הציע:


var colorset = {
dawn:['#fcbd8d', '#a3a7cc'],
noon:['#B7CFEB', '#607EA3'],
dusk:['#805d48', '#718db0'],
night:['#747EAD', '#323752'],
};
var colors = colorset[headerBackground.day_part];
....
whateverYouWant = colors[0]; whateverYouWant = colors[1];

פורסם
  • מחבר

חחח האמת שזה נכון, קצת חשיבה יצירתית הייתה הרבה יותר עוזרת.

תודה רבה

ארכיון

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

דיונים חדשים

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.