【问题标题】:Issue with code running regardless代码运行出现问题
【发布时间】:2015-02-16 15:58:08
【问题描述】:

我有一个html按钮

<input class="showOptions" type="button" style="width:100%" value="<%= (PRCDMU) %>" onclick="programSelector(this.value)" />

这调用了一些 JavaScript

    function programSelector(value){
    var origin = document.getElementById('origin').value();

    if(origin === ""){
            $( "#popup" ).dialog( "open" ); 
    }
    if(origin === "Product Specification"){
        url = 'http://brmappsvr:7018/Enquiries/CMENPROC.rpgle?ProductCode=' + value; 
        window.location.href = url;
    }elseif(origin === "Future Requirements Forecast")
        url = 'http://brmappsvr:7018/Enquiries/CMENPRF.rpgle?ProductCode=' + value;    
        window.location.href = url;
    }

然而,这个过程的一部分是在 Jquery 中弹出。

     $(".showOptions").click(function(){
var $self = this.value;
$( "#popup" ).dialog({
            modal: true,
            width: 465,
            draggable: true,
            buttons: {
            "Product Specification": function() { 
            window.location.href = 'http://brmappsvr:7018/Enquiries/CMENPROC.rpgle?ProductCode=' + $self;  
            $( this ).dialog( "close" );
            },
                "Future Requirements Forecast": function() { //cancel
                window.location.href = 'http://brmappsvr:7018/Enquiries/CMENPRF.rpgle?ProductCode=' + $self;    
                $( this ).dialog( "close" );
            }
        }

});

});

我遇到的问题是弹出窗口看起来很随意,而它只是根据原始变量的内容出现,如果它是空的,则弹出窗口应该可以工作

编辑:

origin 显示在 html 页面上。

    <div align="left">Please click on the<strong> Product Code</strong>, to use it within the <div class="style1" id="origin"><%= (origin) %> program. </div></div>

【问题讨论】:

  • 示例代码不完整,嗯? id='origin' 的元素在哪里?
  • 如果你喜欢,它来自 URL
  • Matt, document.getElementById('origin').value 用于从 html 元素中获取值。在您的编辑中,您的按钮引用了一个查询字符串 (GET) 参数/变量。我们是否假设在页面/资源http://brmappsvr:7018/Enquiries/CMSRPROD.rpgle? 上有一个带有id='origin' 的元素?
  • 你为什么说“我们”?你没说有用的话
  • 你知道,你非常不尊重寻求帮助的人。你提出了一个糟糕的、不完整的问题。你的第一次编辑引发了额外的询问。div 元素没有@ 987654330@ properties..您将需要使用innerText.. 这就是为什么您应该发布一个完整的代码示例来重现该问题的原因.. 但是您是正确的,因为您的直接问题是不相关..您应该打开两个对话框,但第一个对话框由于语法问题 .value().. 而失败,无论由于元素是 div,它都会失败。

标签: javascript jquery html button jquery-ui-dialog


【解决方案1】:

.value() 中的语法错误

应该是

var origin = document.getElementById('origin').value;

代替

var origin = document.getElementById('origin').value();

【讨论】:

    【解决方案2】:

    您已在同一个按钮上附加了 onclick 和 click 事件:

    从点击事件中取出这段代码并添加autoOpen to false;

    $( "#popup" ).dialog({
                    autoOpen: false,
                    modal: true,
                    width: 465,
                    draggable: true,
                    buttons: {
                    "Product Specification": function() { 
                    window.location.href = 'http://brmappsvr:7018/Enquiries/CMENPROC.rpgle?ProductCode=' + $self;  
                    $( this ).dialog( "close" );
                    },
                        "Future Requirements Forecast": function() { //cancel
                        window.location.href = 'http://brmappsvr:7018/Enquiries/CMENPRF.rpgle?ProductCode=' + $self;    
                        $( this ).dialog( "close" );
                    }
                }
    
        });
    
            $(".showOptions").click(function(){
               //based on the value open the dialog.
            }
    

    并删除此onclick="programSelector(this.value)"

    【讨论】:

      猜你喜欢
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-08
      • 2015-05-15
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多