
父子关系的,子级作用域可以调用父级作用域内的变量和函数。而父级不可以拿子级作用域的变量和函数。
作用域平级关系。使用return关键字突破函数作用域。
ajax是异步的请求,success里的函数会在请求成功后才会执行,也就是flag只会在请求完成后才会将datatotal赋值给flag。而return flag是在确认要发起请求后就执行了。所以除非请求完成,否则就是null
不知道你的HdUtils是什么封装的,jqurey的加async: false参数,纯ajax就加asyn: false,这样试试
var searchReportByld = function(shipreportdocId){var flag = null;
var builderShipReport = new HdEzuiQueryParamsBuilder();
if(shipreportdocld != ""){
builderShipReportsetAndClause("shipreportdocId", shipreportdocId, "=", "and");
}
HdUtilsajaxpost({
url: "/webresources/login/work/ShipReport/find",
data: buildershipReportbuild(),
success: function(data){
flag=datatotal;
},
async: false
});
return flag;
};其中parenthtml中含有IFrame并且IFrame指向childhtml。现在需要在parenthtml/childhtml中调用childhtml/parenthtml的一个js方法。
具体的代码实现如下:
parenthtml父页面:
代码如下:
<html>
<head>
<script type="text/javascript">
function parent_click(){
alert("来自父页面");
}
</script>
</head>
<body>
<input type="button" value="调用本页面函数" onclick="parent_click();" />
<input type="button" value="调用子页面函数" onclick='windowframes["childPage"]child_click();' />
<iframe id="childPage" name="childPage" src="innerhtml" width="100%" frameborder="0"></iframe>
</body>
</html>
childhtml子页面:
代码如下:
<html>
<head>
<script type="text/javascript">
function child_click(){
alert("调用的子页面函数");
}
</script>
</head>
<body>
<input type="button" value="调用父页面函数" onclick='parentwindowparent_click();' />
<input type="button" value="调用本页面函数" onclick="child_click();" />
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>标题</title>
<style type="text/css"></style>
<script type="text/javascript">
windowonload=function(){
var oT1=documentgetElementById('text1');
var oT2=documentgetElementById('text2');
var oB=documentgetElementById('btn');
oBonclick=function(){
var a=oT1value;
var b=oT2value;
alert(getValue(a,b));
};
function getValue(a,b){
var sum=parseInt(a)+parseInt(b);
return sum;
}
};
</script>
</head>
<body>
<input type="text" id="text1">
<input type="text" id="text2">
<input type="button" value="获取" id="btn">
</body>
</html>
1语法及返回方式①返回控制与函数结果
语法为:return 表达式;
语句结果函数的执行,返回调用函数,而且把表达式的值作为函数结果返回出去
②返回控制无函数结果
语法为:return;
在大多数情况下,为事件处理函数如果让其返回false,可以防止默认的事件行为例如,默认情况下,点击一个<a>标签元素,页面会跳转到该元素href属性指定的页 而return false就相当于终止符,return true就相当于执行符 在js中return false的作用一般是用来取消默认动作的比如你单击一个链接除了触发你的"onclick"事件以外还要触发一个默认事件就是执行页面的跳转所以这时候如果你想取消对象的默认动作就可以return false来阻止它的动作也就是说如果你想用js代码来局部改变一些数据而不引起页面其他部位的变化,那么你就应该在onclick事件代码的后面加上return false;
在js中,通常用return false来阻止提交表单或者继续执行下面的代码,通俗来说就是阻止执行默认的行为
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)