[英]How can i make my variables visible outside of their range?
我有一个带有一些变量的函数,我想让它在这个函数之外可见,但控制台无法识别它
<b:tag name='script' type='text/javascript'>
(function(){var snapAuthor=AuthorsInfo.filter(function(a){return a.name==='<data:title/>'})[0];
if(snapAuthor!==undefined){
snapAuthor.provided=true;
<b:loop values='data:links' var='link'>
<b:if cond='data:link.name contains "-ad"'>snapAuthor['<data:link.name/>']='<data:link.target.jsEscaped/>';
<b:else/>
<b:switch var='data:link.name'>
<b:case value='rank'/>snapAuthor.rank='<data:link.target.escaped/>';
<b:case value='about'/>snapAuthor.about='<data:link.target.escaped/>';
<b:default/>snapAuthor.links['<data:link.name/>']='<data:link.target/>';
</b:switch></b:if></b:loop>}})();</b:tag>
这是召回功能:
$("#Auth-Sec .LinkList").each(function(){
var e = $(this);
var getName= e.find(snapAuthor.name); // snapAuthor is not defined
if (getName=== AuthorName){
$("body").hide();
}
console.log(getName);
});
请注意snapAuthour
变量的名称。
我尝试 make exmaple,但我最终没有看到 dom 结构:
let snapAuthorList = {};
// there's LinkList class?
// <div class="LinkList">...
<b:tag name='script' type='text/javascript'>
// you must get somu unique ID there
var currentBlockID = 1;
(function() {
var snapAuthor=AuthorsInfo.filter(function(a) {
return a.name==="<data:title/>"
})[0];
// js undefined is type
if(typeof snapAuthor !== "undefined") {
snapAuthorList[currentBlockID] = snapAuthor;
snapAuthor.provided=true;
// pass currentBlockID into dom,
<b:tag name="div" data-id="__currentBlockID__" class="LinkListId">
<b:loop values='data:links' var='link'>
<b:if cond='data:link.name contains "-ad"'>snapAuthor["<data:link.name/>"]="<data:link.target.jsEscaped/>";
<b:else/>
<b:switch var='data:link.name'>
<b:case value='rank'/>
snapAuthor.rank="<data:link.target.escaped/>";
<b:case value='about'/>
snapAuthor.about="<data:link.target.escaped/>";
<b:default/>
snapAuthor.links["<data:link.name/>"]="<data:link.target/>";
</b:switch>
</b:if>
</b:loop>
</b:tag>
}
})();
</b:tag>
// </div>
...
...
...
// some nested scope
<script>
{
{ //
var currentBlockID = $("#Auth-Sec .LinkList .LinkListId").data('id'); // this may be in each loop if on child block
$("#Auth-Sec .LinkList").each(function() {
var e = $(this);
if (typeof snapAuthorList[currentBlockID] !== "undefined") {
var snapAuthor = snapAuthorList[currentBlockID];
var getName = e.find(snapAuthor.name);
if (getName === AuthorName) {
$("body").hide();
}
console.log(getName);
}
});
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.