简体   繁体   English

如何通过onClick传递值并通过jquery中的href加载页面?

[英]How to pass the value through onClick and load a page through href in jquery?

I want to load a page through href and send some data through onClick function. 我想通过href加载页面,并通过onClick函数发送一些数据。 See this is my code. 看到这是我的代码。

<a href='doc-menu-2.html' onClick='doc_menu_2(10)'>Item Name</a>

<script>
myApp.onPageInit('doc-menu-2', function (page) {

    function doc_menu_2(get_cid)
    {
        alert(get_cid);
    }

})
</script>

When I click "Item Name" link, I want to load href page and should pass the doc_menu_2 data to inside function and alert should give value like 10; 当我单击“项目名称”链接时,我想加载href页面,并且应该将doc_menu_2数据传递给内部函数,并且alert应该给出类似10的值;

I tried to find a solution for this here, but I failed. 我试图在这里找到解决方案,但是失败了。

Thanks! 谢谢!

I modified the above code. 我修改了上面的代码。 Try it: 试试吧:

<a href='doc-menu-2.html' onClick='return doc_menu_2(this, 10)'>Item Name</a>

<script>
function doc_menu_2(obj, get_cid)
{
    var href = obj.href;
    console.log(href, get_cid);
    alert(get_cid);
    window.location = obj.href+'?id='+get_cid
    return false;
}
</script>

I was working on it today, and just wanted to post my work around. 我今天正在研究它,只想发布我的工作。

<a href='doc-menu-2.html?parameter_you_need=10'>

End if You want to send to some Tab in page 如果要发送到页面中的某些选项卡,则结束

<a href='doc-menu-2.html?parameter_you_need=10#tab2'>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM