我有一个textarea,我想计算每行的行和价格,然后将数量添加到Stripe结帐。
<textarea id="textarea-1" rows="15" maxlenght="540" placeholder="Type or paste text here">
</textarea>
输入
Hello World!
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam
condimentum metus eget facilisis convallis. Nam facilisis magna quis
pretium ultricies.
脚本中的计数/输出
Hello World!
Lorem ipsum dolor sit amet, cons
ectetur adipiscing elit. Aliquam
condimentum metus eget facilisis
convallis. Nam facilisis magnaqu
is pretium ultricies.
行数应为7。
var flatFee = '70.00';
var perRow = '10.00';
function rowController() {
//Textarea as string
var text = document.getElementById("textarea").value;
//Split string into array with 32 characters in each
var rowSplit = text.val().split("\n", 32);
//Count arrays (7)
console.log(rowSplit.length);
}
//Take string array
var rows = rowSplit.length(this.value);
//Counted arrays and add value
var additionalFees=0;
if (count.rows > 2) {
additionalFees = perRow * (count.rows - 2);
}
var amount = parseFloat(flatFee) + parseFloat(additionalFees);
console.log(amount);
最终金额应该能够放入条带变量。无论如何,这是一般的想法。控制台可以查看它是否重要。
非常感谢帮助。