我需要在href属性中调用javascript中的函数,该属性本身正在另一个javascript函数中传递。
$('head').append('<link type="text/css" rel="stylesheet" href="'document.write(getBaseURL());'/dao_comingsoon/assets/css/layoutArabic.css"/>');
但它不起作用。
这是getBaseURL函数
function getBaseURL() {
var url = location.href; // entire url including querystring - also: window.location.href;
var baseURL = url.substring(0, url.indexOf('/', 14));
if (baseURL.indexOf('http://localhost') != -1) {
// Base Url for localhost
var url = location.href; // window.location.href;
var pathname = location.pathname; // window.location.pathname;
var index1 = url.indexOf(pathname);
var index2 = url.indexOf("/", index1 + 1);
var baseLocalUrl = url.substr(0, index2);
return baseLocalUrl + "/";
}
else {
// Root Url for domain name
return baseURL + "/";
}
}
答案 0 :(得分:1)
应该是这样的:
$('head').append('<link type="text/css" rel="stylesheet" href="' + getBaseURL() + '/dao_comingsoon/assets/css/layoutArabic.css"/>');