Javascript jquery没有';在ajax中加载页面后,似乎无法加载
嗨,我在加载另一个页面时遇到了问题我有一个页面a和页面b,页面a有一个ajax加载页面b,页面b加载并运行jquery非常完美,直到我点击页面a,然后页面b中的jquery似乎没有人能帮我吗 阿贾克斯 加载AJAX的第1页和第二页Javascript jquery没有';在ajax中加载页面后,似乎无法加载,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,嗨,我在加载另一个页面时遇到了问题我有一个页面a和页面b,页面a有一个ajax加载页面b,页面b加载并运行jquery非常完美,直到我点击页面a,然后页面b中的jquery似乎没有人能帮我吗 阿贾克斯 加载AJAX的第1页和第二页 <script src="add.js"></script> <a href="javascript:get()">Live Chat</a> <div id='content' class='content'&g
<script src="add.js"></script>
<a href="javascript:get()">Live Chat</a>
<div id='content' class='content'></div>
第2页,第1页使用工作JQUERY加载,如果由它自己加载,但在AJAX加载此页后不工作
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>Test selctions</title>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#' + $('#selection option:selected').text().toLowerCase()).show();
$('#selection').change(function () {
$('.op').hide();
$('#' + $('#selection option:selected').text().toLowerCase()).show();
});
});
</script>
<style type="text/css">
#plane ,#boat,#car ,#other {
display: none;
}
</style>
</head>
<body>
options:
<select id='selection'>
<option>Pls choose</option>
<option value='1' id='1'>Car</option>
<option value='2' id='2'>Plane</option>
<option value='3' id='3'>Boat</option>
<option value=''>Other</option>
</select><div>
<div id='car' class='op'>you have chosen a car</div>
<div id='plane' class='op'>you have chosen a plane</div>
<div id='boat' class='op'>you have chosen a boat</div>
<div id='other' class='op'>others</div>
</div>
</body>
</html>
测试选择
$(文档).ready(函数(){
$('#'+$('#选择选项:已选定').text().toLowerCase()).show();
$('#selection')。更改(函数(){
$('.op').hide();
$('#'+$('#选择选项:已选定').text().toLowerCase()).show();
});
});
#飞机、船、汽车、其他{
显示:无;
}
选项:
请选择
汽车
飞机
船
另外
你选了一辆车
你选择了一架飞机
你选择了一条船
其他
谁能帮我做这个,我们会非常感激的!谢谢 使用jquery的live()或$(document).on()函数
在第1页上编写第2页的所有jquery函数,并使用live()或$(document).on()函数。
它会起作用的 “AJAX加载页面”到底是什么意思?我没有看到实际“get”函数的代码(add.js也很神秘)。为什么不在这一部分中使用jquery?它在第二个代码中,我如何在jquery中做到这一点?谢谢我现在就尝试一下,谢谢你,againit在jquery中运行得很好,再次感谢!酷,很高兴你解决了这个问题!你不是在说jQuery的
.live()
函数吧?我知道live()不受欢迎。但是您可以使用$(document).on()。如果我使用它,它会安全吗?是的,它会安全的。!你可以用它。@prytsh它不仅不受欢迎,而且已经不存在了。
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>Test selctions</title>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#' + $('#selection option:selected').text().toLowerCase()).show();
$('#selection').change(function () {
$('.op').hide();
$('#' + $('#selection option:selected').text().toLowerCase()).show();
});
});
</script>
<style type="text/css">
#plane ,#boat,#car ,#other {
display: none;
}
</style>
</head>
<body>
options:
<select id='selection'>
<option>Pls choose</option>
<option value='1' id='1'>Car</option>
<option value='2' id='2'>Plane</option>
<option value='3' id='3'>Boat</option>
<option value=''>Other</option>
</select><div>
<div id='car' class='op'>you have chosen a car</div>
<div id='plane' class='op'>you have chosen a plane</div>
<div id='boat' class='op'>you have chosen a boat</div>
<div id='other' class='op'>others</div>
</div>
</body>
</html>