[英]Jquery tabs - use onclick function to get a content
After having fetched external content via Ajax, I want to get an internal content. 通过Ajax获取外部内容之后,我想获取内部内容。 For that I tried to use
onclick
but it doesn't work. 为此,我尝试使用
onclick
但它不起作用。 I have an error saying: 我有一个错误说:
XMLHttpRequest cannot load javascript:void(0);.
XMLHttpRequest无法加载javascript:void(0);。 Cross origin requests are only supported for HTTP.
跨源请求仅支持HTTP。
HTML: HTML:
<div id="tabs">
<ul>
<li><a href="#tab1">tab1</a></li>
<li><a href="#tab2">tab2</a></li>
<li><a href="javascript:void(0);" onclick="javascript:loadTest();">tab3</a></li>
</ul>
<div id="tab1">
<p>blabla</p>
</div>
<div id="tab2">
<p>blabla</p>
</div>
</div>
JQUERY: JQUERY:
function loadTest(){
return "this content must be displayed tab3";
}
How can I get any data from the client to put it into a div corresponding to tab3 我如何从客户端获取任何数据以将其放入对应于tab3的div中
Since you're already using jQuery UI Tabs , I would suggest you to make use of activate
events . 由于您已经在使用jQuery UI Tabs ,我建议您使用
activate
事件 。
$(function () {
$("#tabs").tabs({
activate: function (event, ui) {
alert(loadTest());
}
});
});
Why do you use a onClick? 为什么要使用onClick? jQuery has a function to handle content that is not yet on the page.
jQuery具有处理页面上尚未存在的内容的功能。
You should use the .on
function from jQuery. 您应该使用jQuery中的
.on
函数。 You can do it like this: 您可以这样做:
$(document).ready(function()
{
$('#tabs').on('click', 'li', loadtest)
});
JSfiddle: http://jsfiddle.net/DyRQZ/ JSfiddle: http : //jsfiddle.net/DyRQZ/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.