黑莓上的 Javascript 回调

发布于 2024-08-28 09:03:33 字数 574 浏览 5 评论 0原文

我正在开发一个移动项目,我有一个在后端动态生成的脚本,然后附加到文档(html 页面)。桌面浏览器似乎正确附加了脚本并调用脚本中的任何函数,但是,我无法在黑莓手机上发生这种情况。我知道正在附加脚本,因为我可以在附加脚本后发出警报。我只能让它调用脚本中的函数。

例如,如果我有这样的代码:

var scriptText = document.createElement('script');
scriptText.type = 'text/javascript';
scriptText.id = 'thisScript';
scriptText.innerHTML = 'alert("hello");';
document.getElementById('idName').appendChild(scriptText);

alert(document.getElementById('thisScript')); //Alerts the script element.

这将在桌面浏览器甚至 iPhone/iPodTouch 中发出“hello”警报,但不会在 BlackBerry 浏览器中发出警报。有人知道为什么吗?或者是否有修复/破解?

I'm working on a mobile project, and I have a script that is dynamically generated on the backend and then appended to the document (the html page). Desktop browsers seem to append the script correctly and call any functions in the script, however, I can't get this to happen on Blackberry phones. I know that the script is being appending because I can alert it after I append it. I just can get it to call the function in the script.

For example, if I have code like this:

var scriptText = document.createElement('script');
scriptText.type = 'text/javascript';
scriptText.id = 'thisScript';
scriptText.innerHTML = 'alert("hello");';
document.getElementById('idName').appendChild(scriptText);

alert(document.getElementById('thisScript')); //Alerts the script element.

This will alert 'hello' in desktop browsers and even the iPhone/iPodTouch, but not BlackBerry's. Anyone have any idea why? Or if there's a fix/hack?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咋地 2024-09-04 09:03:33

BB 设备上的 Javascript 支持并不全面。您可以执行基本功能,但 DOM 操作等高级功能没有很好的支持。大多数移动设备都是如此,Android、iPhone 和 WebOS 除外。较新版本的 BB 设备将解决此问题。

Javascript support on BB devices is not comprehensive. You can perform basic functions, but advanced features such as DOM manipulation do not have great support. This is true of most mobile devices, Android, iPhone and WebOS excepted. Newer versions of BB devices will address this.

离去的眼神 2024-09-04 09:03:33

您是否考虑过使用 JavaScript 的 jQuery 库?您只需要包含 jQuery 脚本库:

<script type="text/javascript" src="jquery.js" ></script>

...然后在 jQuery 的 read() 函数中动态添加您需要的警报:

$(document).ready(function() {
    $('#header').append('<div class="testButton" onclick="alert(123)">Menu</div>');

    //or just like this:
    alert('hello 123');

Have you looked into using the jQuery library for javascript? You would merely need to include the jQuery script library:

<script type="text/javascript" src="jquery.js" ></script>

...then dynamically add your alert however you needed to within jQuery's ready() function:

$(document).ready(function() {
    $('#header').append('<div class="testButton" onclick="alert(123)">Menu</div>');

    //or just like this:
    alert('hello 123');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文