日期:2014-05-16  浏览次数:20339 次

Jqeury 取iframe 的值
Html 代码
HTML code

<html>
<body>
<iframe id="xx" name="xx"></iframe>
</body>
</html>



iframe 代码
HTML code

<html>
<body>
<input id="xx" name="xx" value="result"></input>
</body>
</html>



怎么在第一个html用javascript 得到iframe 中的input 的值, 用jquery 更好

------解决方案--------------------
HTML code

<html>
<body>
<iframe id="test" src="3.html" onload="alertValue(this, 'a')"></iframe>
<script>
    function alertValue(t, id){
        var v;
        if( t ){
            if( t.contentDocument ){ // 非ie
                v = t.contentDocument.getElementById(id).value;
            }else if( t.Document ){  // ie
                v = t.Document.getElementById(id).value;
            }
        }
        alert( v )
    }
</script>
</body>
</html>