javascript - 有关于ajax获取到的数据问题
天蓬老师
天蓬老师 2017-04-11 09:20:43
[JavaScript讨论组]

在a.html中有ul,现在ul中有三个li,我现在是每点击一个li通过ajax获取到对应的数据,
然后在b.html中有三个a标签,问如何能实现在b.html中单击a标签跳到a.html中对应li中并得到相应的数据???

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(2)
天蓬老师

以下是伪代码,仅供参考

b.html

<a href="a.shtml?li=0>跳转到LI_A并取得数据</a>

a.html

<li class="myli">li_a</li>
<li class="myli">li_b</li>
<li class="myli">li_c</li>

$('.myli').click(function () {
    loadData($(this).index());
});

// 进入页面判断参数,然后点击对应LI标签
window.onload = function () {
    var index = getQuery('li')
    $('.myli').get(index).click();
}
大家讲道理
这个demo你看下:
前台:
<html>
    <meta charset="utf-8">

    <head>
        <script type="text/javascript" src="jquery.min.js"></script>
        <script type="text/javascript">
$(function()
{
    $(document).on('mouseout', '[name="state"]', function()
    {
        var html;
        var partialState = $(this).val();
        $.getJSON("getStates.php",
        {
            partialState: partialState
        }, function(states)
        {
            $('input').val(states[0]);
            $.each(states, function(i, value)
            {
                html += value;
                $("#results").html(html);
            });
        });

    });
});

        </script>
    </head>

    <body>
        <input type="text" name="state" autocomplete="off" />
        <br>
        <p id="results"> </p>
    </body>

</html>

后台:
<?php
  error_reporting(E_ALL);
  ini_set('display_errors', 1);

  $con = mysqli_connect("localhost", "root", "")
  or die("Failed to connect to the server: " . mysql_error());

  mysqli_select_db($con, "dedecms")
  or die("Failed to connect to the database: " . mysql_error());

  $partialStates = strtoupper($_GET['partialState']);

  if(!$partialStates)
  {
     echo "###";
  }
  else
  {
     $states = mysqli_query($con,"select typename  from dede_arctype where typename like '%$partialStates%'") or die(mysql_error());
     $sources = array();
   while($row = mysqli_fetch_array($states)) {
       $sources[] = $row['typename'];
   }
   header('Content-Type: application/json');
   echo json_encode($sources);
  }
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号