I m 寻找在外部档案中张贴变量的方法。
类似:
<script type="text/javascript" src="/js/script-starter.js?var=value"></script>
然后我要说几句(因此,价值)。 这样做是否可行?
谢谢!
I m 寻找在外部档案中张贴变量的方法。
类似:
<script type="text/javascript" src="/js/script-starter.js?var=value"></script>
然后我要说几句(因此,价值)。 这样做是否可行?
谢谢!
Yes, it is possible. You will have to look for all script
tags in the DOM (make sure the DOM is loaded before attempting to look in it) using the document.getElementsByTagName function, loop through the resulting list, find the corresponding script and parse the src
property in order to extract the value you are looking for.
大致如下:
var scripts = document.getElementsByTagName( script );
for (var i = 0; i < scripts.length; i++) {
var src = scripts[i].src;
// Now that you know the src you could test whether this is the script
// that you are looking for (i.e. does it contain the script-starter.js string)
// and if it does parse it.
}
关于<代码>src的分类,属性是指从中提取指示值的查询,您可使用。
如果该笔文字是服务器式文字,接收可变的盘点和作为产出回归的javascript代码,则有可能。
How about declaring the variable before script file loading:
<script type="text/javascript">var myVar = "Value"</script>
<script type="text/javascript" src="/js/script-starter.js"></script>
因此,你可以在你的文字中使用这一变量。 这可能是最容易的方法之一。
为什么不把变数隐藏在一或一页。
<a id="myHiddenVar" style="display:none;">variables</a>
之后,请见您。 j 随同接触
var obj = document.getElementById("myHiddenVar").innerHTML;
或 j
var obj = $("#myHiddenVar").text();
function getJSPassedVars(script_name, varName) {
var scripts = $( script ),
res = null;
$.each(scripts, function() {
var src = this.src;
if(src.indexOf(script_name) >= 0) {
varName = varName.replace(/[[]/,"\[").replace(/[]]/,"\]");
var string = new RegExp("[\?&]"+ varName +"=([^&#]*)"),
args = string.exec(src);
if(!args.length) {
res = null;
} else {
res = args[1];
}
}
});
return res;
}
console.log(getJSPassedVars( script-starter.js , var ));
在我看来,我的手法结构如下:
MyApp/
index.html
jquery.js
my.js
以上职能载于my.js
with console.log
,并将其列入index.html>。
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.