Php 代码在JSFIDLE中工作,但在localserver中不工作

Php 代码在JSFIDLE中工作,但在localserver中不工作,php,javascript,jquery,html,jsfiddle,Php,Javascript,Jquery,Html,Jsfiddle,请帮我修一下这个 我有一个代码链接,它在JSFIDLE中运行良好。。。但是如果我把同样的东西放在localhost中,它就不工作了,有什么具体原因吗?我还检查了javascripts和jquery,所有东西都正确嵌入(其他jsfiddle代码工作正常) 有人能告诉我如何放置此代码吗 $('q.clickMe1').click(function () { // find first of following DIV siblings // with class "textBox" and togg

请帮我修一下这个

我有一个代码链接,它在JSFIDLE中运行良好。。。但是如果我把同样的东西放在localhost中,它就不工作了,有什么具体原因吗?我还检查了javascripts和jquery,所有东西都正确嵌入(其他jsfiddle代码工作正常)

有人能告诉我如何放置此代码吗

$('q.clickMe1').click(function () {
// find first of following DIV siblings
// with class "textBox" and toggle it

$(this).nextAll('div.sri1:first').show();
$('div.sri1:visible').not($(this).nextAll('div.sri1:first')).toggle();
});
html代码

<q class="clickMe1">Hire</q>
<br />
<div class="sri1"> - This text will be toggled</div>

 <q class="clickMe1">Manage</q>
 <br />
 <div class="sri1"> - This text will be toggled 2</div>
租用

-此文本将被切换 管理
-此文本将切换为2
jsiddle默认情况下将代码包装在
onload
中,这就是它工作的原因。是小提琴,因为我禁用了超负荷包装,所以它不起作用

要使其适合您,请按如下方式包装:

$(document).ready(function() {
    $('q.clickMe1').click(function () {
        // find first of following DIV siblings
        // with class "textBox" and toggle it
        $(this).nextAll('div.sri1:first').show();
        $('div.sri1:visible').not($(this).nextAll('div.sri1:first')).toggle();
    });
});
$(document).on('click', 'q.clickMe1', function () {
    //...your code here
});
假设您使用的是jQuery 1.7或更高版本,您可以避免这种包装,而是使用
.on()
来代替:

$(document).ready(function() {
    $('q.clickMe1').click(function () {
        // find first of following DIV siblings
        // with class "textBox" and toggle it
        $(this).nextAll('div.sri1:first').show();
        $('div.sri1:visible').not($(this).nextAll('div.sri1:first')).toggle();
    });
});
$(document).on('click', 'q.clickMe1', function () {
    //...your code here
});

-无加载且仍在工作。

发生了什么错误或问题是什么?您是否将代码包装在
文档中。准备好了
处理程序?默认情况下,JSFIDLE会为您这样做。您上面的javascript是否在
$(document).ready()块中哈哈,阿尔尼塔克。几乎同步!没有错误,但当我们点击“text1”或“text2”时不会发生任何事情,我认为脚本没有在JSFIDLE中运行bcos,而是在加载时运行jqery1.72。。。。但是如何在我的php页面中实现呢?我已经将脚本代码放在脚本代码中,将html放在会话中。如果您将选择框更改为不换行,那么它在JSFIDLE中将无法工作。这只是一个方便的从JSFIDLE包装它。哦,我的上帝,我怎么会错过这个。。。。对不起,Guyzz打扰你了……现在工作正常了……谢谢你的明确解释。。shadow@Archer“未在其个人资料中设置显示名称的用户不会得到通知”()-无论如何,判断他的“接受历史记录”我相信他迟早会接受它的。:-)@阴影巫师谢谢你的信息-我不知道。以后我会省吃俭用的;)