【问题标题】:Aaccessing button properties from another jsp file从另一个 jsp 文件访问按钮属性
【发布时间】:2015-02-10 08:35:06
【问题描述】:

我在 a.html 中禁用了按钮,在 b.html 中禁用了一些 xyz 按钮。 当点击 b.html 中的 xyz 按钮时,a.html 中的禁用按钮应该会被启用。

我已经尝试了两天,但没有成功。你能帮帮我吗?

【问题讨论】:

  • 您是在 b.html 内加载 a.html 还是反之亦然。它们是如何联系起来的?
  • 您应该提供您尝试过的代码。解释什么不能按预期工作以及出现的任何错误消息(如果有)。
  • a.html 是学生界面,b.html 是教师界面。当老师点击他的按钮时,学生的按钮应该被启用。我没有做任何加载,我只是创建了 2 个 html 文件。
  • @SMadhu 如果两者都是不同的文件,没有任何关系,您不能直接禁用它。相反,您可以在学生的数据库中维护一个标志变量来跟踪信息。根据其值启用和禁用
  • @San Krish 谢谢.......它与数据库中的标志变量一起使用......

标签: html jsp button dom-events


【解决方案1】:

如果只是简单的 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>

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 2017-10-17
      • 1970-01-01
      • 2013-05-06
      • 1970-01-01
      • 2014-10-13
      相关资源
      最近更新 更多