0

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>

ジャバスクリプト - >

    $('.cde').click(function(){
    var n_window = window.open("submit.html");
    $(n_window).ready(function(){
        $('#inp').focus(function(){
            $('#mybutton').val('cns');
        })
    })
})
4

1 に答える 1

2

で使用できるのは現在のドキュメントのみ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');
            });
        }
    });
});

フィドル

于 2013-05-22T20:56:08.293 に答える