V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
cirton

为什么使用 html 函数后找不到新子页面上的 div?

  •  
  •   cirton · Mar 27, 2019 · 2751 views
    This topic created in 2602 days ago, the information mentioned may be changed or developed.

    js 内容如下:

    function xxx(){
      var xpath="...";
      
    	$.get(xpath + ".html", function (data) {
     			$('#' + getPath(xpath)).html(data);
    	});
    	
    	....
    	....
    	
        
    	$("#aaa").css({"height": "300px", "width": "600px", "position":"relative"});
    }
    

    html 函数运行成功,可以看到子页面。 aaa 是子页面里的 div 标签,但是为什么找不到该标签?

    子页面格式如下:

    <div id="menu" class="row">
    	<div id="menu-1" class="row">
    		<div class="col-1">
    			<div class="panel panel-default">
    				<div class="panel-heading">aaa</div>
    				<div class="panel-body">
    					<div id="aaa"></div>
    				</div>
    			</div>
    		</div>
    		...
            ...
    
    3 replies    2019-06-05 16:01:00 +08:00
    wly19960911
        1
    wly19960911  
       Mar 27, 2019
    ......

    基础知识,异步回调,你的代码必须写到加载结束后的事件里面。
    johnhsm2333
        2
    johnhsm2333  
       Mar 27, 2019
    异步,楼上已经回复了。
    saberlove
        3
    saberlove  
       Jun 5, 2019
    编程时注意代码的运行时机
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3261 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 13:58 · PVG 21:58 · LAX 06:58 · JFK 09:58
    ♥ Do have faith in what you're doing.