nEmEc,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<div>
<label>
Число 1:
<input type="number" id="numberA">
</label>
</div>
<div>
<label>
Число 2:
<input type="number" id="numberB">
</label>
</div>
<div>
Попыток:
<input type="number" id="popytki">
</div>
<div>
<button onclick="data1 = allFunction(); console.log (data1);">Попробовать</button>
</div>
<script>
function allFunction() {
function getFormValueA() {
let a = document.getElementById('numberA').value;
return a;
};
let a = getFormValueA();
function getFormValueB() {
let b = document.getElementById('numberB').value;
return b;
};
let b = getFormValueB();
function getPopytkiValue() {
let c = document.getElementById('popytki').value;
return c;
};
let c = getPopytkiValue();
let data = {
chislo_1: a,
chislo_2: b,
popytki: c,
};
return data;
};
let data1 = allFunction();
</script>
</body>
</html>
|
Нет. Я ввожу туда цифры и нажимаю кнопку.
Например: 1, 2, 3 ввожу Результат: ДО Object { "chislo_1": "1", "chislo_2": "2", "popytki": "3" } |
а лучше так
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<div>
<label>
Число 1:
<input type="number" id="numberA">
</label>
</div>
<div>
<label>
Число 2:
<input type="number" id="numberB">
</label>
</div>
<div>
Попыток:
<input type="number" id="popytki">
</div>
<div>
<button onclick="allFunction(); ">Попробовать</button>
</div>
<script>
function getObj() {
function getFormValueA() {
let a = document.getElementById('numberA').value;
return a;
};
let a = getFormValueA();
function getFormValueB() {
let b = document.getElementById('numberB').value;
return b;
};
let b = getFormValueB();
function getPopytkiValue() {
let c = document.getElementById('popytki').value;
return c;
};
let c = getPopytkiValue();
let data = {
chislo_1: a,
chislo_2: b,
popytki: c,
};
return data;
};
function allFunction()
{
let data1 = getObj();
console.log ('data1', data1)
// тут делайте что хотите с объектом
}
</script>
</body>
</html>
|
Получилось!!! Спасибо огромное!
|
| Часовой пояс GMT +3, время: 16:57. |