禁用.aspx文件中的HTML按钮不起作用

时间:2013-09-05 14:56:55

标签: html asp.net

我正在尝试编写一个禁用按钮的脚本,具体取决于用户在上一页上输入的内容。但是,当我直接将disabled =“disabled”放入输入行时,我甚至无法禁用该按钮。当我在.html页面上输入完全相同的代码时,它工作正常,按钮被禁用。我对网络开发很陌生,我不明白这里发生了什么。我指定<!DOCTYPE html>,按钮位于<html>标记内。知道为什么这个简单的命令不起作用吗?

<input type="button" id="b1" value ="How much can weight loss reduce my risk?" style="white-space:normal" disabled="disabled"/>

编辑:所有代码

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm3.aspx.vb" Inherits="WebApplication2.WebForm3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  
    <link rel="stylesheet" type="text/css" href="StyleSheet1.css" />
    <title></title>
    <style type="text/css">
        #b1 {
            height: 137px;
            width: 137px;
        }
    </style>
</head>
<body>


         <script type="text/javascript">
             google.load("visualization", "1", { packages: ["corechart"] });
             google.setOnLoadCallback(init);

             function init() {
                 var data = google.visualization.arrayToDataTable([
                   ['Years Out Risk', 'Risk'],
                   ['5 Year Risk',  <%= TKR5%>],
                   ['10 Year Risk', <%= TKR10%>],
                   ['15 Year Risk', <%= TKR15%>],
                   ['20 Year Risk', <%= TKR20%>],
                   ['25 Year Risk', <%= TKR25%>],
                   ['30 Year Risk', <%= TKR30%>],
                   ['Lifetime Risk', <%= TKRLife%>]
                 ]);

                 var options = {
                     title: 'My Daily Activities',
                     'width': 400,
                     'height': 300,
                     animation: {
                         duration: 3000,
                         easing: 'out'
                     },
                     vAxis: { 
                         viewWindowMode:'explicit',
                         viewWindow: {
                             max:1,
                             min:0
                         }
                     }



                 };
                 var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
                 var button1 = document.getElementById('b1');
                 var button2 = document.getElementById('b2');

                 function drawChart() {
                     button1.disabled = true;
                     button2.disabled = true;
                     google.visualization.events.addListener(chart, 'ready',
                         function () {
                             button1.disabled = false;
                             button2.disabled = false;
                         });

                     chart.draw(data, options);
                 }
                 button1.onclick = function () {
                     data.setValue(0, 1, <%= nobTKR5%>);
                     data.setValue(1, 1, <%= nobTKR10%>);
                     data.setValue(2, 1, <%= nobTKR15%>);
                     data.setValue(3, 1, <%= nobTKR20%>);
                     data.setValue(4, 1, <%= nobTKR25%>);
                     data.setValue(5, 1, <%= nobTKR30%>);
                     data.setValue(6, 1, <%= nobTKRLife%>);
                     drawChart();
                 };
                 button2.onclick = function () {
                     data.setValue(0, 1, <%= TKR5%>);
                     data.setValue(1, 1, <%= TKR10%>);
                     data.setValue(2, 1, <%= TKR15%>);
                     data.setValue(3, 1, <%= TKR20%>);
                     data.setValue(4, 1, <%= TKR25%>);
                     data.setValue(5, 1, <%= TKR30%>);
                     data.setValue(6, 1, <%= TKRLife%>);
                     drawChart();
                 }

                 drawChart();

             }

    </script>
    <div id="chart_div"></div>


    <input type="button" id="b1" value ="How much can weight loss reduce my risk?" style="white-space:normal" disabled="disabled"/>
    <input type="button" id="b2" value ="Reset risk" style="white-space:normal"/>

    </body>
</html>

2 个答案:

答案 0 :(得分:2)

如果您的按钮为HtmlButton,则可以尝试使用

myBtn.Attributes.Add("disabled","disabled");

它适合我。

答案 1 :(得分:0)

尝试使用     &LT; asp:Button id =&#34; b1&#34;文本=&#34;提交&#34;禁用=#&34;禁用&#34; RUNAT =&#34;服务器&#34; /&GT;