为什么我不能在velocity模板中显示/隐藏此元素

bq9c1y66  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(201)

我正在使用velocity模板创建页面。该页面有一些切换按钮。其中一个切换按钮加载为选中状态。选中该切换时,不应显示一个div。取消选中切换时,可以看到div。
下面是velocity页面中的相关代码


# set ($javaScriptWarningDiv = 'display=none')

## this does not work. the div loads and is visible. it also does not disappear when toggled off. could be what causes it?

## for a little bit this was actually hiding it but I've made so many changes to my code that I forgot what it was set to.

## also tried: #set ($hideThisShit = 'display=none') but that didn't hide it either

<div class="field-group top-label" style="text-align:left">
 <label for="allowJavaScript">
       <b>$i18n.getText("${atlassian.plugin.key}.config.allowJavaScript")</b>
 </label>
 $i18n.getText("${atlassian.plugin.key}.config.allowJavaScript.desc")
 <br/>
 <aui-toggle id="allowJavaScript" name="allowJavaScript" label=""
 ## when this is toggled it should change the visibility of the div below
    #if ($allowJavaScriptEnabled) checked #end $readonlyDisabled>
 </aui-toggle>
</div>
 <br/>
 <div class="field-group top-label javaScriptWarningDiv" style="text-align:left" id="hideThisShit">

## the class with the value javaScriptWarningDiv is the one that should be showed/hidden

## I have tried grabbing from the id but it has failed

## I tried setting display="none" here but I was unable to use js/jquery to set display="block"

## I even tried setting . javaScriptWarningDiv { display: none } in my css but that just means it is permanently hidden

    <label for="allowJavaScriptWarning">
        <b>$i18n.getText("${atlassian.plugin.key}.config.allowJavaScriptWarning")</b>
    </label>
    $i18n.getText("${atlassian.plugin.key}.config.allowJavaScriptWarning.desc")
    <br/>
    <aui-toggle id="allowJavaScriptWarning" name="allowJavaScriptWarning" label="">

    </aui-toggle>
 </div>

下面是js/jquery

AJS.toInit(function($) {
...
    AJS.$("#allowJavaScript").click(function(e) {
       // $(".javaScriptWarningDiv").hide();
       // not even sure if this is worth including
        $("#allowJavaScript").change(function(){
          if (this.checked){
            alert("is checked");
            $(".javaScriptWarningDiv").hide();
          //  $(".javaScriptWarningDiv").css("display", "none");
          } else {
            alert("is not checked")
            $(".javaScriptWarningDiv").show();
           // $(".javaScriptWarningDiv").css("display", "block");
        }
    // this is what I'm currently trying. not sure why it isn't working. 
    // also I noticed that when I click the toggle the first time the alert doesn't appear. but when I click it a second time 1 alert shows up. clicked a third time and 2 alerts show up. etc...
    // also the first time I click the toggle and it gets toggled off, there is no alert. the first alert comes from me clicking the toggle so it goes from off to on. 
    });
});

我曾尝试在if/else语句中使用以下代码位,但都没有成功

$(".javaScriptWarningDiv").css("display", "block") 
$("#hideThisShit").attr("display", "block")

在我试过的速度文件中


# set ($javaScriptWarningDiv = 'display=none')

当它真正起作用时,我可以在inspector中确认该属性正在设置。在某一点上,这实际上隐藏了它,但再一次,我已经改变了我的代码这么多,我不知道确切地说,它被设置为什么。我将它与.css()和.attr()方法结合使用,但两者都不起作用。不太清楚到底发生了什么。
我也尝试过用下面两行代码启动我的js函数,但都没有什么不同。

// $(document).on("click", "#allowJavaScript", function() {
// $(document).ready(function() {

如果有括号丢失或拼写错误,它不是在代码本身,而是我没有复制和粘贴它。如果您看到的是#javascriptwarningdiv而不是。javascriptwarningdiv这是因为在我将javascriptwarningdiv添加到类之前,它最初是一个id。没有改变任何事情。不确定我做错了什么,或者我还能做什么。谢谢
更新:从vm文件中删除#set行,在div中设置display=“none”,并删除$(“.javascriptwarningdiv”).hide();行我可以加载显示隐藏div的页面。当我关闭时,将显示div。当我打开它时,div消失了。这是正确的行为。仍然有我认为不好的多个警报,对吗?无法隐藏要加载的div。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题