尝试控制javascript新窗口想知道什么时候表单输入区域填充并且想知道如何控制新窗口中的元素。id,按钮等等。下面是我的测试示例
submit.html ->
<!DOCTYPE HTML>
<html lang="en-US">
<head>
</head>
<body>
<form>
<input type="input" id="inp">
<input type ="button" id="mybutton" value ="Dell">
</form>
</body>
</html>
javascript ->
$('.cde').click(function(){
var n_window = window.open("submit.html");
$(n_window).ready(function(){
$('#inp').focus(function(){
$('#mybutton').val('cns');
})
})
})
只有当前文档可以与ready()
一起使用,并且您不需要它用于新窗口中的事件处理程序。你可以这样做:
$(function() {
$('.cde').on('click', function() {
var n_window = window.open("test2.html");
n_window.onload = function() {
$('#inp', n_window.document).on('focus', function() {
$('#mybutton', n_window.document).val('cns');
});
}
});
});
小提琴