不能使用全局变量,想往$_c.jsonaa传递 json 赋值给result_01 ,求助高手,怎么实现?

yld2017 2017-03-11 05:48:06


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<script type="text/javascript">

function jsonhandle(result){
alert("k");
var json = result;
alert(json);

}
jsonhandle("aa");
$_c={};
$_c.jsonaa = function(options){

var result_01 = json;// 这里不能使用 jsonhandle("aa") 函数 ,不能使用全局变量
}



</script>

<body>
</body>
</html>





不能使用全局变量,
想往$_c.jsonaa传递 json 赋值给result_01 ,怎么实现?
...全文
133 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yld2017 2017-03-29
  • 打赏
  • 举报
回复


以下代码在IE无效,在火狐有效


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<script type="text/javascript">
$_c={};
$_c.aa = function(aca)
{
alert(aca);
}
$_c.aa("测试a=a");

for(var i=0; i<10; i++)
{
localStorage.setItem(i,i);
}

for(var i=0; i<10; i++)
{
var a =localStorage.getItem(i);
//alert(a);
}


function jsonhandle(result){
// alert("k");
var json = result;

localStorage.setItem("json", json);
alert("json=="+json);


}
jsonhandle("aa");

$_c.jsonaa = function(options){
var result_01 =localStorage.getItem("json");
alert("result_01=="+result_01);
}

$_c.jsonaa(1);
</script>
</body>
</html>


天际的海浪 2017-03-11
  • 打赏
  • 举报
回复

function jsonhandle(result){
	jsonhandle.json = result;

}
jsonhandle("aa");
$_c={};
$_c.jsonaa = function(options){
	
	var result_01 = jsonhandle.json;// 这里不能使用 jsonhandle("aa") 函数 ,不能使用全局变量
}

灰太狼2017 2017-03-11
  • 打赏
  • 举报
回复
function jsonhandle(result){ alert("k"); var json = result; localStorage.setItem("json", json); alert(json); } jsonhandle("aa"); $_c={}; $_c.jsonaa = function(options){ var result_01 =localStorage.getItem("json");

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧