JQuery从动态内容加载动态内容
I was wondering if someone would be able to help or point me in a direction. I am looking to make a web application like a quiz. What I need is to be able to load dynamic content off a dynamical created button or href in this case that will link to the other content. So far it doesnt seem to be functioning in that i get a page not found every time i click the button. doesnt seem to be passing the .php through the name. I have tested this outside of the dynmaic content div and it works fine but i really need it to work inside. What I have so far:
我想知道是否有人能够帮助或指出我的方向。我希望制作一个像测验一样的Web应用程序。我需要的是能够从动态创建按钮或href加载动态内容,在这种情况下将链接到其他内容。到目前为止它似乎没有起作用,因为我每次单击按钮都会找不到页面。似乎没有通过名称传递.php。我已经在dynmaic内容div之外测试了它,它工作正常,但我真的需要它在里面工作。到目前为止我所拥有的:
index.php
<body>
<div class="container_12">
<div id="content">
<!--dynamic content loads here-->
</div>
</div>
</body>
Login.php
<h1> Login Page </h1>
<p> this is a test to c if works </p>
<a href='Suitable'>Hello</a> <!--button that doesnt work-->
general.js
$(document).ready(function() {
//initial
$('#content').load('Login.php');
//Handle widget Clicks
$('div#content a').click(function() {
var page = $(this).attr('href');
$('#content').load('pages/' + page +'.php');
return false;
});
});
Suitable.php
<h1> Working </h1>
<!-- content thats not loading off button-->
3 个解决方案
#1
2
you should delegate the click
event for dynamically loaded elements, try the following:
您应该为动态加载的元素委派click事件,请尝试以下操作:
$('#content').on('click', 'a', function(e) {
e.preventDefault()
var page = $(this).attr('href');
$('#content').load('pages/' + page +'.php');
});
更多相关文章
- 如何为django模板中的标记创建动态id
- 在HTML中添加<br /为何整篇内容却全部顶格了
- 如何在HTML标记上打印/显示动态值?
- asp:Repeater 动态换行
- 如何让这段插入的innerHTML 里动态赋予的函数跑起来!
- 花式框内的内容需要响应
- 【求助】python xpath如何提取html中的如下的内容?
- 为什么我的DIV小于其内容?
- 使用xpath查找包含特定内容的span