gpt4 book ai didi

asp.net - 将服务器端 vb.net 转换为客户端 javascript

转载 作者:行者123 更新时间:2023-11-30 06:08:20 26 4
gpt4 key购买 nike

我有一个我很久以前写的函数,它运行良好,但我想通过在 Javascript 中做同样的工作来加快这个过程并减轻服务器负载。

我似乎能够获取文本框值,但我似乎无法设置文本框值(我是一个 JS 菜鸟)。任何人都可以帮忙将我的 VB.NET 代码转换为等效的 JS 代码吗?

Protected Sub txtSellingPrice_TextChanged(ByVal sender As Object, ByVal e As EventArgs) _
Handles txtSellingPrice.TextChanged

Dim SellingPrice As Double = Double.Parse(txtSellingPrice.Text.Replace("$", ""))
Dim BallanceSheet As Double = If(txtBalanceSheet.Text = "", 0, Double.Parse(txtBalanceSheet.Text.Replace("$", "")))
Dim DownPayment As Double = If(txtDownPayment.Text = "", 0, Double.Parse(txtDownPayment.Text.Replace("$", "")))

txtGoodWill.Text = SellingPrice - BallanceSheet
txtBalance.Text = SellingPrice - DownPayment
txtSellingPriceMult.Text = SellingPrice

End Sub

到目前为止,我已经了解了这一点,但我不确定如何取得更多进展。

function txtSellingPrice_OnChange() {
var txtSellingPrice = document.getElementById('<%=txtSellingPrice.ClientID %>')
var txtBalanceSheet = document.getElementById('<%=txtBalanceSheet.ClientID %>')
var txtDownPayment = document.getElementById('<%=txtDownPayment.ClientID %>')


}

最佳答案

function txtSellingPrice_OnChange() {
//Get your elements
var txtSellingPrice = document.getElementById('<%=txtSellingPrice.ClientID %>');
var txtBalanceSheet = document.getElementById('<%=txtBalanceSheet.ClientID %>');
var txtDownPayment = document.getElementById('<%=txtDownPayment.ClientID %>');

var txtGoodWill = document.getElementById('<%=txtGoodWill.ClientID %>');
var txtBalance = document.getElementById('<%=txtBalance.ClientID %>');
var txtBalance = document.getElementById('<%=txtBalance.ClientID %>');

//Your if empty value checks
var sellingPrice = txtSellingPrice.value.replace('$', '');
sellingPrice = (sellingPrice == '' ? 0 : sellingPrice);
var ballanceSheet = txtBalanceSheet.value.replace('$','');
ballanceSheet = (ballanceSheet == '' ? 0 : ballanceSheet);
var downPayment = txtDownPayment.value.replace('$','');
downPayment = (downPayment == '' ? 0 : downPayment);

txtGoodWill.value = (sellingPrice - ballanceSheet);
txtBalance.value = (sellingPrice - downPayment);
txtSellingPriceMult.value = sellingPrice;

}

关于asp.net - 将服务器端 vb.net 转换为客户端 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2484442/

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