javascript/jquery:需要在jquery中子字符串 [英] javascript/jquery: Need to substring in jquery
问题描述
<script type="text/javascript">
$(function(){
$("a[rel='tab']").click(function(e){
e.preventDefault();
pageurl = $(this).attr('href');
$.ajax({url:pageurl+'?rel=tab',success: function(data){
$('#right_column').html(data);
}});
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
return false;
});
});
</script>
当使用<a>
标记内的rel="tab"
单击链接时,以前的代码是我用来用内容更新div元素的内容.
The previous code is what I am using to update a div element with content when a link is clicked with rel="tab"
inside the <a>
tag.
示例<a>
标签:
<a href="index.php?v1=variable1&v2=variable2" rel="tab">Click Here</a>
所以,现在,我需要更新上面的javascript代码的以下几行,以将index.php的子字符串排除在链接之外...
So now, I need to update the following lines of the javascript code above to substring out index.php out of the link...
$.ajax({url:pageurl+'?rel=tab',success: function(data){
$('#right_column').html(data);
}});
但是需要将javascript的最后部分的完整URL保留为pageurl.
But need to keep the full url for the last section of the javascript as pageurl.
我该怎么做?
我对此进行了研究,并尝试实现此处列出的答案:如何在jquery中进行子字符串 但似乎无法使其正常工作.
I did research on this and tried implementing the answer listed here: How to substring in jquery but couldn't seem to get it to work.
推荐答案
您似乎想这样做,尽管我不确定为什么.
It looks like you want to do this, though I'm not sure why.
$.ajax({url:pageurl.replace('index.php', '') +'&rel=tab' ...
请注意concat上的&
而不是?
,因为URL已具有?
Note the &
not ?
on the concat, as the URL already has ?
这篇关于javascript/jquery:需要在jquery中子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!