javascript - 在javascript中设置变量

标签 javascript jquery ios jquery-mobile

我需要创建基于 A 标签 ID 的 javascript 片段,窗口将导航到正确的 html 文件。我把一些东西放在一起,当我查看它时,它应该可以工作,但由于某种原因它没有。这是我得到的。

<script> 
    $(document).bind('pageinit', function() { 
        $('a').each(function (index){
            var elementId = $(this).attr("id"); 
            elementId= elementId + '.html';
            $(function(){ 
                $(elementId).click(function (event) { 
                    event.preventDefault(); 
                    window.location.assign(elementId); 
                }); 
            }); 
        });
    }); 
</script>

这部分是为了让我可以在 ios 网络应用程序中加载外部 html 而无需退出网络应用程序窗口

$(function(){ $(elementId).click(function (event) { 
    event.preventDefault(); 
    window.location.assign(elementId); 

我是不是把变量写错了,怎么办?任何帮助将不胜感激

最佳答案

我会大胆猜测:

$(function(){ 
    $('a').on('click', function(e) {
        e.preventDefault();
        window.location.assign(this.id + '.html'); 
    });
});

关于javascript - 在javascript中设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14859170/

相关文章:

javascript - 使用 lodash 在对象数组中展平数组

javascript - 使用 jQuery 显示多个结果

ios - 单个 AVPlayerItem 中的两个声音淡入淡出

javascript - 错误 : Permission denied to access property 'handler'

ios - ReactiveCocoa 和代表

iOS 自定义 View (.XIB) 按钮绑定(bind)不起作用

javascript - 我的 Controller [AngularJs] 出错

javascript - 从语言环境日期字符串中获取时刻对象

javascript - 聚合物 : Style Parent Element from dom-repeat data item

jQuery 移动 + Phonegap : Ajax calls not working on Android Emulator