从另一个jsp文件访问按钮属性

时间:2015-02-10 08:35:07

标签: html jsp button javascript-events

我在a.html中禁用了按钮,在b.html中禁用了一些xyz按钮。 单击b.html中的xyz按钮后,应启用a.html中的禁用按钮。

我正在尝试这个,因为2天但没有得到你可以帮助我。

2 个答案:

答案 0 :(得分:0)

如果它只是简单的html页面,您可以使用jQuery/ JavaScript来执行此操作。这是一个简单的例子:

a.html:

<body>
  <input id="aButton" type="button" value="A Button">

  <script type="text/javascript">
    $(document).ready(function() {
        var enableAButton=getUrlParameter("enable");

        if(enableAButton == "true"){
            $('#aButton').prop('disabled', false);
        }else{
            $('#aButton').prop('disabled', true);//disabled by default
        }
    });

    function getUrlParameter(sParam)
    {
        var sPageURL = window.location.search.substring(1);
        var sURLVariables = sPageURL.split('&');
        for (var i = 0; i < sURLVariables.length; i++) 
        {
            var sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] == sParam) 
            {
                return sParameterName[1];
            }
        }
    } 
  </script>
</body>

b.html:

<body>
  <input id="bButton" type="button" value="B Button">
  <script type="text/javascript">
    $("#bButton").click(function(){
        window.location.href="a.html?enable=true"
    });
  </script>
</body>

答案 1 :(得分:0)

如果两者都是没有任何关系的不同文件,则无法直接禁用它。相反,您可以在学生的数据库中维护一个标志变量来跟踪信息。根据其价值启用和禁用。

相关问题