Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript/Jquery在单击导航时添加标签?_Javascript_Jquery_Html - Fatal编程技术网

使用JavaScript/Jquery在单击导航时添加标签?

使用JavaScript/Jquery在单击导航时添加标签?,javascript,jquery,html,Javascript,Jquery,Html,我想能够点击标签导航到新的页面,我不想使用链接,因为它必须有一个按钮的感觉 html: <label id="+"pagego"+" style="+"text-align:center;"+"font-size:x-large;"+">"+ data[i].ProcessName +"</label> “+data[i].ProcessName+” 我知道这看起来很奇怪,但我在jquery的for循环中使用了这个标签,用我从web服务获得的数据填充标签,现在我如何才

我想能够点击标签导航到新的页面,我不想使用链接,因为它必须有一个按钮的感觉

html:

<label id="+"pagego"+" style="+"text-align:center;"+"font-size:x-large;"+">"+ data[i].ProcessName +"</label>
“+data[i].ProcessName+”
我知道这看起来很奇怪,但我在jquery的for循环中使用了这个标签,用我从web服务获得的数据填充标签,现在我如何才能点击这个标签,我看到人们谈论window.location.href,甚至有一些人谈论$(#pagego)。单击(function()){我是这方面的新手,我想知道如何让这个标签导航到新的页面!谢谢


我建议使用:cordova1.9/html5/javascript/jquery,首先将样式移动到css块中

css:


#佩戈{
文本对齐:居中;
字号:x大号;
}
脚本:

<script type="text/javascript">
    $(document).ready(function () {
        $('#pagego').value = data[i].ProcessName;

        $('#pagego').onclick(function(){
            // to submit the form:
            $('#formID').submit();

            // to navigate:
            document.location.href = "new page address";
        });
    }
</script>

$(文档).ready(函数(){
$('#pagego')。value=data[i]。ProcessName;
$('#pagego').onclick(function(){
//提交表格:
$('#formID')。提交();
//要导航:
document.location.href=“新建页面地址”;
});
}
以及您的html:

<input id="pagego"><input>

“+数据[i]。进程名+”
请注意,DOM中的多个项不能具有相同的ID

<label id="+"pagego"+i+" style="+"text-align:center;"+"font-size:x-large;"+" onclick='redirectme()'>"+ data[i].ProcessName +"</label>

<script>
function redirectme()
{
location.href='example.html'
}
</script>
“+data[i].ProcessName+”
函数重定向我()
{
location.href='example.html'
}

“…因为它必须有按钮的感觉”-那么为什么不使用按钮呢?请注意,如果您在循环中创建一系列标签,并且循环中有这行代码,那么您将为它们提供所有相同的id属性,这是无效的html。请发布所有相关的代码来说明问题?使用链接并以任何方式对其进行样式设置,使其“感觉像一个按钮”你完全理解我需要什么谢谢你的快速回复这正是我想要的,我只做了一个改变就是我使用了window.location.href!不过我有一个问题,有时候标签不想被点击,我需要在它们工作之前重新加载页面?你知道为什么会发生这种情况吗?
<label id="+"pagego"+" style="+"text-align:center;"+"font-size:x-large;"+">"+ data[i].ProcessName +"</label>
<label id="+"pagego"+i+" style="+"text-align:center;"+"font-size:x-large;"+" onclick='redirectme()'>"+ data[i].ProcessName +"</label>

<script>
function redirectme()
{
location.href='example.html'
}
</script>