【问题标题】:Jquery div to div load only works in operaJquery div 到 div 加载仅适用于歌剧
【发布时间】:2012-10-23 21:37:07
【问题描述】:

几天前,我在堆栈上找到了一些解决我的问题的方法。代码如下:

HTML

<a class="link" data-toggle="modal" href="link1.php" >Link 1</a>
<a class="link" data-toggle="modal" href="link2.php" >Link 2</a>
<a class="link" data-toggle="modal" href="link3.php" >Link 3</a>

<div class="modal hide fade" id="myModal"></div>

jQuery

$("a.link").click(function(){
    $("#myModal").html($(this).attr("href")); 
    /*$("#myModal").load($(this).attr("href"));*/
    return false;
});​

但是,这只适用于 Opera。在所有其他浏览器中,链接永远不会在mymodal div 中打开。 完整代码在这里

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style>
#prvidiv {
    width:360px;
    height: 220px;
    border: 1px;
    padding: 5px;
    font-family: cool_font, sans-serif;
    font-size:24px;
    color:#0000CC;
    background-color:transparent;
}
#levideookvir{
float:left;
width: 760px;
height:800px;
margin-right:0px;
margin-top: 0px;

}
</style>
<script src="jqery/jquery.min.js"></script>

</head>

<body>
<script language="javascript">
 $(document).ready(function() {
  $("a.link").click(function(e){
        $("#levideookvir").html($(this).attr("href")); 
       $("#levideookvir").load($(this).attr("href"));
       window.alert('Request complete');
         e.preventDefault();

  })
 });​
    </script>

<div id="prvidiv">
Ovde ide link<br />
<a class="link" href="test2.html">Klikni me</a><br />
</div>
<div id="levideookvir" >OVDE REY</div>

</body>
</html>

因为它很奇怪...我什至没有收到我在 Chrome、Safari 或 FF 中运行此脚本时定义的 ALERT。 正如我所说...只在歌剧中工作。

【问题讨论】:

    标签: jquery load opera href attr


    【解决方案1】:

    jQuery 的.html() 方法只接受一个HTML 字符串作为参数。您的代码中有正确的语法,但它已被注释掉。

    这就是你需要的(如果我理解正确的话):

    $("a.link").click(function(e) {
        $("#myModal").load($(this).attr("href"));
        e.preventDefault();
    });​
    

    【讨论】:

    • 不... :(不工作。我知道代码的注释部分,它没有在我的代码中注释。我哪里写错了?我会将整个代码粘贴到新评论中
    • 我必须添加....无论我尝试什么,结果都是一样的。只有 OPERA 可以将数据加载到定义的 DIV 中。
    【解决方案2】:

    准确地说... 这是代码(当然我不会同时使用两个代码块,所以这不是错误)

      <script type="text/javascript">
        $(document).ready(function(){   
    <!--THIS ONE IS WORKING-IT CAN BE OPENED IN ANY BROWSER   -->
     $("a.link").click(function(){
        $("#levideookvirsrcamoga233").load($(this).attr("href"));
        return false;
        });
        });
    //THIS ONE BELLOW IS NOT WORKING
        $("a.link").click(function(){
        $("#levideookvirsrcamoga233").load($(this).attr("href"));
        return false;
    
    });​
    });
    </script>
    

    已解决!在我的键盘上编写代码时更改字符集是问题所在。

    【讨论】:

      猜你喜欢
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      相关资源
      最近更新 更多