简体   繁体   English

Firefox,IE Opera —功能未定义

[英]Firefox, IE Opera — function not defined

DoRowApp function is not defined in FF, IE, Opera. 在FF,IE,Opera中未定义DoRowApp函数。 Works in Chrome. 在Chrome中工作。

function DoRowApp(id) {
document.getElementById('ANSWER.TTQ.MENSYS.1.').value = id;
document.getElementById('ANSWER.TTQ.MENSYS.2.').click();
return true;}

This is the html 这是HTML

<a target="_blank" href="javascript:DoRowApp("_40558067");" title="Application Form"><img border="0"></a> 

which we are getting from xml 我们从xml得到的

<cell>Application Form^javascript:DoRowApp("'||edit.mhd_code||'");^_blank</cell></row>

As always..help would be awesome. 一如既往..帮助会很棒。

At the same time this function works: 同时,此功能有效:

function DoRow(id) {
'use strict';
var LowerBound, UpperBound, StartAppNo, BaseAppNo, i;
LowerBound = mygrid.getRowIndex(id) - 25;
UpperBound = mygrid.getRowIndex(id) + 100;
StartAppNo = 25;
BaseAppNo  = 0;
mygrid.selectRowById(id, true, true, false);
localStorage.clear();
if (mygrid.getRowIndex(id) - 25 > 0) {
    StartAppNo =  25;
}
else {
        StartAppNo =  mygrid.getRowIndex(id);
    }
localStorage.setItem("9999", StartAppNo);
if (LowerBound < 0) {LowerBound = 0; }
for (i = LowerBound; i <= UpperBound; i++) {
    if (mygrid.getRowId(i)) {
        localStorage.setItem(BaseAppNo, mygrid.getRowId(i));
        BaseAppNo++;
    }
}
document.getElementById('ANSWER.TTQ.MENSYS.1.').value = id;
document.getElementById('ANSWER.TTQ.MENSYS.2.').click();
return true;}

And the HTML for this is HTML就是

<a target="_blank" href="javascript:DoRow("_40558067");" title="Application Form"><img border="0"></a>

I recommend you to let the javaScript out of your xml: 我建议您让javaScript脱离xml:

<cell>Application Form^'||edit.mhd_code||'</cell>

Or even better 甚至更好

<cell rowId="'||edit.mhd_code||'">Application Form</cell>

Then you produce the following HTML: 然后,您生成以下HTML:

<a href="#" class="RowButton" data-rowId="_40558067" title="Application Form"><img border="0"></a>

Now you can add the event handler generic in javaScript: 现在,您可以在javaScript中添加通用的事件处理程序:

function DoRowApp (rowId) { /**/ }

// Simplified onLoad
window.onload = function () {

    // Enum all elements with class="RowButton"
    var rowButtons = document.getElementByClassName("RowButton");
    for (var i = 0; i < rowButtons.length; i++) {

        // Closure for i and rowButton
        (function (i, rowButton) {

            // get the data-rowId attribute
            var rowId = rowButton.getAttribute("data-rowId");

            // Simplified addEventHandlerListener
            rowButton.onclick = function () {

                // call your function
                DoRowApp(rowId);

                // return false to prevent a href
                return false;
            };

        })(i, rowButton[i]); 
    }
};

I don't see where you are "opening" another webpage; 我看不到您正在“打开”另一个网页的位置; in javaScript redirecting to another page is 在javaScript中重定向到另一个页面是

window.location.href = "url";

To ensure it's the top-most frame, use 为了确保它是最上面的框架,请使用

window.top.location.href = "url";

To open a new window, use window.open 要打开一个新窗口,请使用window.open

window.open(url, "_blank");

Further readings 进一步阅读

As you see, to have a solid base to write cross-browser javaScript code, it is highly recommendable to use jQuery. 如您所见,为了拥有坚实的基础来编写跨浏览器的JavaScript代码,强烈建议使用jQuery。 The only other way to write simple javaScript is to only use latest browser versions - but how to tell that the users... 编写简单的JavaScript的另一种方法是仅使用最新的浏览器版本-但如何告诉用户...

In jQuery the above would look like: 在jQuery中,上面看起来像:

$(function () {  // simplified jQuery(document).ready(function () {

    // Enum all elements class="RowButton" and add click handler
    $(".RowButton").click(function (e) {
        e.preventDefault();

        // Call your function
        DoRowApp($(this).attr("data-rowId"));

    });

});

As it looks like you're javaScript starter, I have the urge you to not use w3schools, read why on http://w3fools.com ! 看起来您是javaScript入门者,我强烈建议您不要使用w3schools,请在http://w3fools.com上阅读原因! Better read 更好地阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Firefox和Opera中可用,但在IE8中不可用 - Works in Firefox & Opera, but not in IE8 javascript在chrome / opera / IE中不起作用,但是firefox非常好! - javascript not working in chrome/opera/IE but firefox is excellent! 如何在Firefox,Opera和IE中检测浏览器插件? - How to detect browser addons in Firefox, Opera and IE? Chrome,Firefox和Opera中的CSS转换问题,但IE中没有 - Issue with CSS transitions in Chrome, Firefox and Opera, but not IE IE / Firefox / Opera之间的模糊Javascript区别 - Obscure Javascript difference between IE / Firefox / Opera JavaScript搜索功能在Chrome,Safari和Opera中运行良好,但在IE和Firefox中永远存在 - JavaScript search function works great in Chrome, Safari, and Opera, but takes forever in IE and Firefox indexOf不是Firefox中的一个函数,Opera可以在IE中工作,indexOf在javascript中替代测试字符串包含? - indexOf is not a function in Firefox, Opera but works in IE, indexOf alternative in javascript to test string contains? Javascript FormData函数可用于Chrome和Opera,但不适用于Firefox - Javascript FormData function works with Chrome and Opera but not Firefox $(window).unload(function(){}); 是不是在火狐和歌剧中被解雇了? - $(window).unload(function(){}); is not fired in Firefox and opera? Javascript-Opera 11.60和IE 8上的排序功能出现问题 - Javascript - Issue with sort function on Opera 11.60 and IE 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM