Jak*_*ion 2 javascript jquery hide
将 json 解析为指定的跨度标签后,我想自动隐藏英制标签 currentimperial 和 Forecastimperial 但当我尝试执行此操作时
$('#currentimperial').hide();
$('#forecastimperial').hide();
Run Code Online (Sandbox Code Playgroud)
并在 chrome 中查看结果并在控制台中查看,我看到而不是
style="display: none; "
Run Code Online (Sandbox Code Playgroud)
他们实际上有
style="display: inline; "
Run Code Online (Sandbox Code Playgroud)
这是我在 jsBin 上的整个 javascript 和 html http://jsbin.com/efaguv/edit#javascript,html
感谢我收到的任何帮助。
我认为问题是你没有考虑到你的 ajax 调用是异步的这一事实。
正在发生的事情的一个简单得多的示例:
1 jQuery(document).ready(function($) {
2 $('#warning').remove('#warning');
3 $.ajax({
4 url: 'http://api.wunderground.com/api/APIKEYREMOVED/geolookup/conditions/forecast/q/51.773079,-1.591353.json',
5 dataType: "jsonp",
6 success: function(parsed_json) {
7 $('#currentimperial').fadeIn(1000).append(+temp_f+ '℉ ');
8 }
9 });
10
11 $('#celcius').hide();
12 $('#currentimperial').hide();
13 $('#forecastimperial').hide();
14 });
Run Code Online (Sandbox Code Playgroud)
因为(在完整代码中)ajax 成功回调使元素可见(使用.fadeIn()),最终结果是它们可见。
您可以隐藏 ajax 成功回调中的元素吗?
| 归档时间: |
|
| 查看次数: |
8116 次 |
| 最近记录: |