2012-11-04 10 views
1

在下面的代码,我想改变的代码读取行:
如何使我的jQuery代码识别参数的URL,然后选择一个代码行

$("#commentload"+ID).prepend(html); 

因此,如果在URL中找到参数order=1,例如,http://my.com?order=1然后它应该执行。

$("#commentload"+ID).append(html); 

而不是

$("#commentload"+ID).prepend(html); 

希望你明白我的意思。

$(document).ready(function(){ 
    // Update Status 
    $(".update_button").click(function(){ 
     var updateval = $("#update").val(); 
     var dataString = 'update='+ updateval; 
     if(updateval==''){ 
     alert("Please Enter Some Text"); 
     } else { 
     $("#flash").show(); 
     $("#flash").fadeIn(400).html('Loading Update...'); 
     $.ajax({ 
      type: "POST", 
      url: "message_ajax.php?CID=" + CID + "&Id="+Id, 
      data: dataString, 
      cache: false, 
      success: function(html){ 
       $("#flash").fadeOut('slow'); 
       $("#commentload"+ID).prepend(html); 
       $("#update").val(''); 
       $("#update").focus(); 
       $("#stexpand").oembed(updateval); 
      } 
     }); 
     } 
     return false; 
    }); 
    //commment Submit 
}); 
+0

我已经为你格式化了你的文章。请记住缩进代码四个空格来格式化它。造型通常会识别它是哪种语言。如果不是这样,你可以用'<! - language:lang-etc - >'作为前缀,''''是'''','''''''''''''''''''''css'样式表“或类似的。 – Daedalus

+0

谢谢代达罗斯!我对这种造型仍然很陌生。你那时溺爱我,但我会从中吸取教训。非常感谢。 –

回答

4

你可以使用location.href当前的URL(或location.search,因为你只是在查询部分感兴趣)。使用正则表达式搜索它的参数,例如:

if (/order=1/.test(location.href)) 
    $("#commentload"+ID).append(html); 
else 
    $("#commentload"+ID).prepend(html); 

如果你需要一个更通用的解决方案,请参阅this related question(或this one,通过@naveen的建议)。

+0

非常感谢!!!!我一直在追赶一个多小时。这是最有帮助的。 –

+1

+1:另一个更全面的链接http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values/901144#901144 – naveen

相关问题