[英]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.