admin管理员组文章数量:1431740
I'm trying to set the base href with JQuery by reading a PHP file.
Why does $("base").load("ip.php");
work but $("base[property='href']").load("ip.php");
doesn't?
Of course what I need is to set the href parameter only, not the content of base.
I found I could get it working by using $("head").load("ip.php");
but would like to know why above isn't working.
I'm trying to set the base href with JQuery by reading a PHP file.
Why does $("base").load("ip.php");
work but $("base[property='href']").load("ip.php");
doesn't?
Of course what I need is to set the href parameter only, not the content of base.
I found I could get it working by using $("head").load("ip.php");
but would like to know why above isn't working.
-
what do you mean with "this work"
$("base").load("ip.php");
, how do this set the href of base? or this:$("head").load("ip.php");
?? – reyaner Commented Sep 30, 2014 at 7:26 -
load
doesn't change the href attribute, it loads content from your ip.php and puts it intobase
element, if you want to change href you can do$('base').attr('href', 'ip.php')
– paulitto Commented Sep 30, 2014 at 7:33
4 Answers
Reset to default 3Try something like this to set href value
$('base').attr('href','http://www.google.');
Its depend how your file ip.php is
For example
ip.php
<?php
echo 'http://www.google.';
?>
Then
$.get('ip.php',function(response){
$("base").attr("href", response);
});
I don't know exactly, but in my opinion, u got the meaning of the selector wrong. I think [property='href'] is not a valid selector. href is the property you should search for, and not the value.
You can select DOM-elements with jquery using $("base"). Additionally you can use a key-value bination to search for certain attribute-values of your element.
$("a[href$='']")
With this selector you would select elements with a href attribute which ends with ''.
So the point is: you still select the DOM-element and NOT a part of that element. But your search is better specified.
just need :
window.location = "http://yoursite.php";
dont use load, use $.ajax!
$.ajax({
url: "ip.php"
}).done(function (data) {
$("base").attr("href", data);
});
本文标签: javascriptjquery set base hrefStack Overflow
版权声明:本文标题:javascript - jquery set base href - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745580249a2664577.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论