Home > Web Front-end > HTML Tutorial > I just learned ajax. How to get the url value? A very awkward question_html/css_WEB-ITnose

I just learned ajax. How to get the url value? A very awkward question_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:12:18
Original
1101 people have browsed it

比如 li链接是

  • test


  • jquery   
    $("li").click(function(){
    $.get("test.asp",{id:x},
    function(data,textStatus){
    $(".div1").html(data)}
    })

    代码很简单,现在就是如何将url 后面id的值赋值给x ,{id:$(this).text}不行,$(this).text的值是空的,不是aaa







    回复讨论(解决方案)

    $("li").click(function(){
    var x = $(this).find('a')[0].href.split('=')[1];
    $.get("test.asp",{id:x},
    function(data,textStatus){
    $(".div1").html(data)}
    })

    试试

    $("li").click( function() {    var x = $(this).find("a").attr("href");    x = x.substring(x.lastIndexOf("=") + 1);    $.get("test.asp", {id: x}, function(data) {        $(".div1").html(data);    });});
    Copy after login

    <li><a href="test.asp?id=aaa">test</a></li><script>function queryString(url , key){    var regex_str = "^.+\\?.*?\\b"+ key +"=(.*?)(?:(?=&)|$|#)"    var regex = new RegExp(regex_str,"i");    if(regex.test(url)) return RegExp.$1;    return undefined;}$("li").click(function(){    var url = $(this).children('a').attr('href');    alert(queryString(url,'id'))$.get("test.asp",{id:queryString(url,'id')},		function(data,textStatus){		$(".div1").html(data)		}  )})</script>
    Copy after login

    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template