我如何使用Java脚本向Aspx页面传递简单Html按钮的值 [英] How I Pass The Value Of Simple Html Button Using Java Script To Aspx Page

查看:66
本文介绍了我如何使用Java脚本向Aspx页面传递简单Html按钮的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <  !DOCTYPE     html     PUBLIC     -  // W3C // DTD     XHTML     1.0     Transitional // EN   http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >  

< html xmlns = http:// www.w3.org/1999/xhtml\">
< head >
< title > < / title >
< / head >
< script type = text / javascript >
function myFunction(val){

alert(val);
document.getElementById(opr)。value;
document.forms [0] .submit();
}

< / script >
< body >
< 表格 id = myForm action = Default.aspx 方法 = 获取 >
名字:< 输入 type = text < span class =code-attribute> name = n1 / > ; < br / >
姓氏:< 输入 type = text name = n2 / > < br / > < br / >
< input type = hidden name = opr id = opr / >
< 输入 type = button onclick = myFunction('添加') value = 添加 名称 = opr / >
< input type = 按钮 on单击 = myFunction('Sub') value = Sub name = opr / >
< 输入 type = 按钮 onclick = myFunction('Mul') value = Div name = opr / >
< 输入 类型 = 按钮 onclick = myFunction('Div') value = Mul name = opr / >
< /表格 >
< / body >
< / html >





请Help.Html代码粘贴在这里。值未传递到Default.Aspx页面

解决方案

将该值分配给隐藏字段并在aspx中访问该值

您错过了将参数值分配给隐藏字段opr,其余代码没问题:

 document.getElementById(opr)。value = val ; 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    </head>
<script type="text/javascript">
    function myFunction(val) {

        alert(val);
        document.getElementById("opr").value;
        document.forms[0].submit();
    }

</script>
  <body>
 <form id="myForm" action="Default.aspx" method="get">
First name: <input type="text" name="n1" /><br/>
Last name: <input type="text" name="n2" /><br/><br/>
<input type="hidden" name="opr" id="opr"/>
<input type="button" onclick="myFunction('Add')" value="Add" name="opr" />
<input type="button" onclick="myFunction('Sub')" value="Sub" name="opr" />
<input type="button" onclick="myFunction('Mul')" value="Div" name="opr" />
<input type="button" onclick="myFunction('Div')" value="Mul" name="opr" />
</form>
</body>
</html>



Pls Help.Html Code Paste Here. The Value Does Not Pass To The "Default.Aspx Page"

解决方案

Assign that value to hidden field and access that value in aspx


You have missed out assigning the parameter value to the hidden field opr, the rest of code is fine:

document.getElementById("opr").value = val;


这篇关于我如何使用Java脚本向Aspx页面传递简单Html按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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