Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery没有';t将()追加到新打开的选项卡_Jquery - Fatal编程技术网

jQuery没有';t将()追加到新打开的选项卡

jQuery没有';t将()追加到新打开的选项卡,jquery,Jquery,当我尝试使用append()方法将html插入到通过单击主页中的按钮打开的新选项卡时,我遇到了一个问题。我在网上搜索了答案,但没有找到任何关于我问题的答案。我发现的唯一建议是使用html()而不是append(),但这也不起作用。这是我代码中有问题的部分。您可以忽略ajax调用和变量部分,因为从调试中我可以看出它是有效的#游戏在我的主页上,#editGames是我试图在第二页附加()的部分。谢谢大家! ` $(“#游戏”)。在(“单击“,”.editeaza”,函数()上{ window.ope

当我尝试使用append()方法将html插入到通过单击主页中的按钮打开的新选项卡时,我遇到了一个问题。我在网上搜索了答案,但没有找到任何关于我问题的答案。我发现的唯一建议是使用html()而不是append(),但这也不起作用。这是我代码中有问题的部分。您可以忽略ajax调用和变量部分,因为从调试中我可以看出它是有效的#游戏在我的主页上,#editGames是我试图在第二页附加()的部分。谢谢大家!

`

$(“#游戏”)。在(“单击“,”.editeaza”,函数()上{
window.open(“edit.html”);
$(文档).ready(函数(){
$.ajax({
网址:
"https://games-world.herokuapp.com/games/" +
$(本)
.parent()
.attr(“id”),
方法:“获取”
}).然后(功能(游戏){
变量id=游戏。\u id;
var title=game.title;
var releaseDate=game.releaseDate;
var流派=game.genre;
var publisher=game.publisher;
var image=game.imageUrl;
变量描述=游戏描述;
$(“#编辑游戏”).append(我很笨!

”; }); }); });

`

您需要存储对另一个窗口的引用,并在加载后使用其文档上下文访问其中的元素

试一试


谢谢你的回答。我认为我做错了别的事情,因为您的第一个解决方案对我不起作用,尽管它应该起作用,因为您的plunker演示对我起作用。既然你说第二种方法比较简单,那么你能详细说明一下吗。从第二页的URL获取id后,我应该做什么?我是否需要一个新的脚本页面来链接到该页面,或者我可以只使用普通的脚本页面,在单独的函数中执行AJAX调用和其他操作?您可以在另一个页面中执行AJAX,或者使用服务器端代码来呈现数据。太多的不知道为什么我的第一个解决方案不起作用非常感谢你我用你的第二个建议和URL使它起作用。我不知道这样发送身份证。再次感谢你,在过去的3个小时里,我一直在绞尽脑汁。
$("#games").on("click", ".editeaza", function() {
    window.open("edit.html");
        $(document).ready(function() {
          $.ajax({
          url:
          "https://games-world.herokuapp.com/games/" +
          $(this)
            .parent()
            .attr("id"),
        method: "GET"
      }).then(function(game) {
        var id = game._id;
        var title = game.title;
        var releaseDate = game.releaseDate;
        var genre = game.genre;
        var publisher = game.publisher;
        var image = game.imageUrl;
        var description = game.description;

        $("#editGames").append("<p>I AM DUMB!</p>");
      });
    });
  });
$("#games").on("click", ".editeaza", function() {
  // other window reference
  var otherWindow = window.open("edit.html");
  // let other window load before accessing elements
  $(otherWindow).on('load', function() {
    // document in other window
    var $doc = $(this.document);
    // find() within other document 
    $doc.find("#editGames").append("<p>I AM DUMB!</p>");
  });
});
$("#games").on("click", ".editeaza", function() {
    window.open("edit.html?item_id=" + $(this).parent().attr('id'));
})