我有两页是这样的
Test.html
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script>
$(document).ready(function(){
var w=window.open("search.html","_blank");
w.onload = function(){
setTimeout(() => {
$('#search', w.document).val("test");
$('#search', w.document).trigger("keyup");
}, 5000);
}
});
</script>
和earch.html
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
</head>
<body>
<input type="text" id="search">
</body>
</html>
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script>
$(document).ready(function(){
$("#search").keyup(function(){
alert($(this).val());
});
});
</script>
When Test.html load success, it open window search.html and set search value is test and send event keyup to it. But only set value can happen, keyup cannot send. Please check for me :(