如何使这个JavaScript文件存在于asp.net泛型中 [英] How to make this javascript file present in asp.net generic

查看:56
本文介绍了如何使这个JavaScript文件存在于asp.net泛型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

意味着我知道我们需要在.aspx页面中编写几行代码但是如何编写代码。



Means I know that we need to write few line of code in my .aspx page but how to do it.

function fnadd() {
    debugger;
    var otbA = document.getElementById('txtA');
    var otbB = document.getElementById('txtB');
    var otbres = document.getElementById('txtres');
    var v1 = parseInt(otbA.value);
    var v2 = parseInt(otbB.value);
    otbres.value = v1 + v2;
}
function fnsub() {
    var otbA = document.getElementById('txtA');
    var otbB = document.getElementById('txtB');
    var otbres = document.getElementById('txtres');
    var v1 = parseInt(otbA.value);
    var v2 = parseInt(otbB.value);
    otbres.value = v1 - v2;
}
function fnmul() {
    var otbA = document.getElementById('txtA');
    var otbB = document.getElementById('txtB');
    var otbres = document.getElementById('txtres');
    var v1 = parseInt(otbA.value);
    var v2 = parseInt(otbB.value);
    otbres.value = v1 * v2;
}
function fndiv() {

    var otbA = document.getElementById('txtA');
    var otbB = document.getElementById('txtB');
    var otbres = document.getElementById('txtres');
    var v1 = parseInt(otbA.value);
    var v2 = parseInt(otbB.value);
    otbres.value = v1 / v2;
    
}

推荐答案

<!-- "data-type" attributes only needed for Method 3 -->
<asp:TextBox ID="txtA" data-type="sourceA" runat="server" />
<asp:TextBox ID="txtB" data-type="sourceB" runat="server" />
<asp:TextBox ID="txtResult" data-type="result" runat="server" />

<button onclick="fnaddMethod1(); return false;">Method 1</button>
<button onclick="fnaddMethod2('<%=txtA.ClientID %>', '<%=txtB.ClientID %>', '<%=txtResult.ClientID %>'); return false;">Method 2</button>
<button onclick="fnaddMethod3(); return false;">Method 3</button>

<script type="text/javascript">
    // only needed for Method1
    var sourceA = '<%=txtA.ClientID %>';
    var sourceB = '<%=txtB.ClientID %>';
    var resultId = '<%=txtResult.ClientID %>';
</script>










function fnaddMethod1() {
    if (typeof (sourceA) == "undefined" || typeof (sourceB) == "undefined" || typeof (resultId) == "undefined")
    {
        return;
    }

    var otbA = document.getElementById(sourceA);
    var otbB = document.getElementById(sourceB);
    var otbres = document.getElementById(resultId);
    var v1 = parseInt(otbA.value);
    var v2 = parseInt(otbB.value);
    otbres.value = v1 + v2;
}

function fnaddMethod2(sourceA, sourceB, targetId) {
    var otbA = document.getElementById(sourceA);
    var otbB = document.getElementById(sourceB);
    var otbres = document.getElementById(resultId);
    var v1 = parseInt(otbA.value);
    var v2 = parseInt(otbB.value);
    otbres.value = v1 + v2;
}

// requires jQuery, but there are other ways of getting elements based on attributes if you don't
// want to use jQuery
function fnaddMethod3() {
    var otbA =


' [data-type =sourceA]');
var otbB =
('[data-type="sourceA"]'); var otbB =


' [数据类型= sourceB]);
var otbres =
('[data-type="sourceB"]'); var otbres =


这篇关于如何使这个JavaScript文件存在于asp.net泛型中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆