我如何从iframe表单id检索值,并调用它到我的客户端html。
(客户端html)sample.html
<head>
<script>
function alertThis(){
alert(parent.myframe.formsubmit.a_token.value);
}
</script>
</head>
<body>
<iframe name = "myframe" src="http://domain.com/sample/index.php">
<button onClick = "alertThis();">Click Here</button>
</body>
(服务器端php)index . php
<form name = "formsubmit">
<input id = "a_token" value="<?php echo $_SESSION['user'] ?>"/>
</form>
但是它不返回任何
试试这个代码
<iframe name="myframe" id="myframe" src="http://domain.com/sample/index.php">
function alertThis(){
var content = window.frames['myframe'].document.forms['formsubmit'].elements['a_token'].value;
alert(content);
}
编辑
同样的问题已经排序使用jQuery
获取iframe内部的无线电值
$('#myframe').contents().find('a_token').val()
var doc = window.frames['myframe'].document.getElementById('a_token').value;警报(doc);
试试这个。