gpt4 book ai didi

javascript - 将输入文本乘以 2,在另一个输入中回答

转载 作者:行者123 更新时间:2023-11-28 06:15:20 25 4
gpt4 key购买 nike

Screenshot enter image description here

更新:

这是我的整个 HTML 页面。由于此处的字符限制,底部的一些内容已被删除。只需重复多次即可获得所需的结果。

<!DOCTYPE html>

<html>
<head lang="en">
<meta charset="utf-8">
<link rel="stylesheet" href="css/styles-expenses.css">
<title>CashdUp - Expenses</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script>

$("input").keyup(function(){

var getInId = $(this).attr('id');
var getOutId = $('#'+getInId+'_ans').attr('id');
var getInVal = document.getElementById(getInId).value;

if(!isNaN(getInVal)){

var result = (getInVal * 2);

$('#'+getOutId).val(result);


}
else{
$('#'+getOutId).val("");
alert("Please enter a valid number");
}
});

</script>

</head>
<body class="site-body">

<div class="div-1">

<h1 class="message">Expenses</h1>

</div>

<div class="div-2">

<table class="left-table" style="width:50%">

<th><u>Expense</u></th>
<th><u>Weekly</u></th>
<th><u>Fortnightly</u></th>
<th><u>Yearly</u></th>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1_a" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="input1_a_ans" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="outyear1_a" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

</table>

<table class="right-table" style="width:50%">

<th><u>Expense</u></th>
<th><u>Weekly</u></th>
<th><u>Fortnightly</u></th>
<th><u>Yearly</u></th>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<select class="expense-option">
<option>- Select Option -</option>
<option>Car Insurance</option>
<option>Car Loan</option>
<option>Car Park</option>
<option>Car Registration</option>
<option>Car Servicing</option>
<option>Clothes</option>
<option>Credit Card</option>
<option>Dining Out</option>
<option>Donation</option>
<option>Entertainment</option>
<option>Groceries</option>
<option>Health Insurance</option>
<option>Internet</option>
<option>Mobile Phone</option>
<option>Petrol</option>
<option>Rent / Mortgage</option>
<option>Spending / Pocket Money</option>
<option>Sport</option>
<option>Utilities</option>
</select>
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<input class="expense-option-manual" type="text" placeholder="Expense">
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>

<tr>
<td class="options">
<input class="expense-option-manual" type="text" placeholder="Expense">
</td>

<td><input class="amount" id="input1" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="output1" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="output2" type="text" placeholder="Yearly $" readonly></td>

</tr>
</body>
</html>

部分底部已被切割。

更新:

我现在还更新了我的所有 ID,使它们变得不同。

<td><input class="amount" id="week_a" type="text" placeholder="Weekly $"></td>
<td><input class="amount1" id="outfort_a_ans" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount1" id="outyear_a" type="text" placeholder="Yearly $" readonly></td>

它们从字母“a”延伸到字母“t”以将它们分开。

那么我如何实现一个乘法,在每个表行中输入“week_a”到“week_t”,将其中的数字乘以数字2,并将答案放置在输入的相应行中进入,例如如果数字 2.56 放在 week_g 中,那么答案将在 outfort_g_ans 中为 5.12 等。然后,为了使其变得更复杂,将数字 5.12 乘以 26,然后将该数字在 outyear_g 中显示为 133.12。

最佳答案

工作 Demo

您的代码问题是所有文本框的 ID 都相同。 ID 始终唯一。

所以我对你的代码进行了一些编辑,

$("input").keyup(function(){
var getInId = $(this).attr('id');
var getOutId = $('#'+getInId+'_ans').attr('id');
var getInVal = document.getElementById(getInId).value;

if(!isNaN(getInVal)){
var result = (getInVal * 2);
$('#'+getOutId).val(result);
}
else{
$('#'+getOutId).val("");
alert("Please enter a valid number");
}
});

更新 Fiddle

<td><input class="amount" id="input_c" type="text" placeholder="Weekly $"></td>
<td><input class="amount" id="input_c_ans" type="text" placeholder="Fortnightly $" readonly></td>
<td><input class="amount" id="input_c_year" type="text" placeholder="Yearly $" readonly></td>

这里是脚本,

 var yearResult = (result * 26);
$('#'+getOutyear).val(yearResult);

关于javascript - 将输入文本乘以 2,在另一个输入中回答,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36026528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com