我正在使用货币转换器 Web 服务,并且我编写了一个 Javascript 来显示按钮单击的结果。我希望 javascript 在页面加载时触发。我试着这样做
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Javascript", "function(data);", true);
}
但是该功能仍然没有触发。这是我正在使用的 JS。
<script type="text/javascript">
$(function () {
$('#btnConvert').click(function () {
var amount = $('#txtAmount').val();
var from = $('#ddlfrom').val();
var to = $('#ddlto').val();
$.ajax({ type: "POST",
url: "WebService.asmx/CurrencyConversion",
data: "{amount:" + amount + ",fromCurrency:'" + from + "',toCurrency:'" + to + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var dot = data.d.indexOf(".");
var eg = data.d.substring(0, dot + 2);
var eg1 =data.d.substring(11, 50);
$('#currency_converter_result').html(eg + eg1);
}
});
});
});
</script>