Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery.find()方法不起作用_Javascript_Jquery_Jquery Plugins - Fatal编程技术网

Javascript jQuery.find()方法不起作用

Javascript jQuery.find()方法不起作用,javascript,jquery,jquery-plugins,Javascript,Jquery,Jquery Plugins,我正在从事一个与twitter提要相关的项目,并使用Tweetie master jQuery插件 链接: 但不幸的是,jQuery.find()方法根本不起作用。我试了很多次,但没有发现错误 <script type="text/javascript"> $(document).ready(function() { $('#twitter_feed').twittie({ dateFormat: '%b. %d, %Y', template:

我正在从事一个与twitter提要相关的项目,并使用Tweetie master jQuery插件

链接:

但不幸的是,jQuery.find()方法根本不起作用。我试了很多次,但没有发现错误

<script type="text/javascript">
$(document).ready(function() {
    $('#twitter_feed').twittie({
        dateFormat: '%b. %d, %Y',
        template: '{{avatar}} {{tweet}} {{screen_name}} {{date}}',
        count: 3
    });
    $("#twitter_feed ul").find("li:first").css({"color":"red","border":"2px solid red"});
});
</script>

$(文档).ready(函数(){
$('twitter\u feed')。twittie({
日期格式:“%b.%d,%Y”,
模板:{{avatar}{{tweet}{{screen{u name}}{{date}},
计数:3
});
$(“#twitter_feed ul”).find(“li:first”).css({“color”:“red”,“border”:“2px solid red”});
});

我的项目演示链接:

它不工作,因为当执行
$(“\twitter\u feed ul”).find(“li:first”)
时,没有加载推文,因此不存在
li
。如果我理解twittie,您应该使用回调函数:

$('#twitter_feed').twittie({
    dateFormat: '%b. %d, %Y',
    template: '{{avatar}} {{tweet}} {{screen_name}} {{date}}',
    count: 3
}, function () {
    $("#twitter_feed ul").find("li:first").css({"color":"red","border":"2px solid red"});
});

它不起作用,因为当执行
$(“#twitter_feed ul”).find(“li:first”)
时,没有加载tweet,因此不存在
li
。如果我理解twittie,您应该使用回调函数:

$('#twitter_feed').twittie({
    dateFormat: '%b. %d, %Y',
    template: '{{avatar}} {{tweet}} {{screen_name}} {{date}}',
    count: 3
}, function () {
    $("#twitter_feed ul").find("li:first").css({"color":"red","border":"2px solid red"});
});

我猜twittie()是异步的,所以代码没有等待响应。在twittie返回任何内容之前,代码执行
find
,但什么也找不到。查找
twitti()
回调函数。

我的猜测是
twitti()
是异步的,所以代码没有等待响应。在twittie返回任何内容之前,代码执行
find
,但什么也找不到。查找
twitti()
回调函数。

正如@Holt指出的那样,jquery代码是在填充div之前执行的。 如果只想更改first li的样式,还可以使用CSS:

#twitter_feed ul li:first-child { color: #F00; border: 1px solid #F00;}

正如@Holt指出的,jquery代码是在填充div之前执行的。 如果只想更改first li的样式,还可以使用CSS:

#twitter_feed ul li:first-child { color: #F00; border: 1px solid #F00;}

我认为这应该是可行的,虽然没有测试过,但值得一试

<script type="text/javascript">
$(document).ready(function() {
    $('#twitter_feed').twittie({
        dateFormat: '%b. %d, %Y',
        template: '{{avatar}} {{tweet}} {{screen_name}} {{date}}',
        count: 3
    }).promise().done(function(){
        $("#twitter_feed ul").find("li:first").css({"color":"red","border":"2px solid red"});
    });

});
</script>

$(文档).ready(函数(){
$('twitter\u feed')。twittie({
日期格式:“%b.%d,%Y”,
模板:{{avatar}{{tweet}{{screen{u name}}{{date}},
计数:3
}).promise().done(函数()){
$(“#twitter_feed ul”).find(“li:first”).css({“color”:“red”,“border”:“2px solid red”});
});
});

我认为这应该行得通,虽然没有测试过,但值得一试

<script type="text/javascript">
$(document).ready(function() {
    $('#twitter_feed').twittie({
        dateFormat: '%b. %d, %Y',
        template: '{{avatar}} {{tweet}} {{screen_name}} {{date}}',
        count: 3
    }).promise().done(function(){
        $("#twitter_feed ul").find("li:first").css({"color":"red","border":"2px solid red"});
    });

});
</script>

$(文档).ready(函数(){
$('twitter\u feed')。twittie({
日期格式:“%b.%d,%Y”,
模板:{{avatar}{{tweet}{{screen{u name}}{{date}},
计数:3
}).promise().done(函数()){
$(“#twitter_feed ul”).find(“li:first”).css({“color”:“red”,“border”:“2px solid red”});
});
});

你可以发布你的标记,或者把它和你的JS放在一个环境中,比如:$(“#twitter_feed ul”).find(“li:first”).css({“color”:“red”,“border”:“2px solid red”});在所提供链接的控制台中运行时工作正常。问题是,在twittie Pluginca之后运行时,您发布标记,并可能将标记和JS放入一个环境中,例如:$(“#twitter_feed ul”).find(“li:first”).css({“color”:“red”,“border”:“2px solid red”});在所提供链接的控制台中运行时工作正常。问题是在twittie Plugin之后运行时,你能看到我的演示链接并建议我需要做什么吗?@user3535842我更新了我的答案。根据
$.fn.twitti
的定义,它应该可以工作。你能看到我的演示链接并建议我需要做什么吗?@user3535842我更新了我的答案。根据
$.fn.twittee
的定义,它应该可以工作。根据作者指定的链接上的
tweetie.js
文件,对于
twittee
没有这样的
承诺
功能。事实上,
$.fn.twittie
根本不返回任何内容,因此您将得到一个错误。虽然我没有说“未测试”,但应该通过删除promise()部分来工作。如果删除promise()部分将不起作用,因为正如我已经说过的,
$.fn.twittie
不返回任何可以调用的对象,或者,不管你想做什么,你只需要在未定义的
上调用一个函数即可。好的,深入查看
$.fn.twitti
,你是正确的,你的代码片段也是正确的答案+1根据作者指定的链接上的
tweetie.js
文件,twittie
没有这样的
promise
功能。事实上,
$.fn.twittie
根本不返回任何内容,因此您将得到一个错误。虽然我没有说“未测试”,但应该通过删除promise()部分来工作。如果删除promise()部分将不起作用,因为正如我已经说过的,
$.fn.twittie
不返回任何可以调用的对象,或者,不管你想做什么,你只需要在未定义的
上调用一个函数即可。好的,深入查看
$.fn.twitti
,你是正确的,你的代码片段也是正确的答案+1.