Javascript:正在尝试访问window.variable,但即使在初始化之后它仍保持未定义状态
我在函数1中初始化了4个全局变量,并为函数赋值。当我尝试在下一个函数中访问变量时,只有第一个变量是可访问的。其他的都没有定义 当用户填写基本表单信息时,调用Function1。然后,他被重新定向到高级形态。填写完两个表单后,数据将存储在数据库中 请提供一些解决方案Javascript:正在尝试访问window.variable,但即使在初始化之后它仍保持未定义状态,javascript,variables,global-variables,Javascript,Variables,Global Variables,我在函数1中初始化了4个全局变量,并为函数赋值。当我尝试在下一个函数中访问变量时,只有第一个变量是可访问的。其他的都没有定义 当用户填写基本表单信息时,调用Function1。然后,他被重新定向到高级形态。填写完两个表单后,数据将存储在数据库中 请提供一些解决方案 ````` 函数function1(){ window.name=$scope.data.name; //window.emailc@g.com'; window.varemail=$scope.data.email; window
`````
函数function1(){
window.name=$scope.data.name;
//window.emailc@g.com';
window.varemail=$scope.data.email;
window.varmobile=$scope.data.mobile;
window.varlocation=$scope.data.location;
console.log(window.name);
console.log(window.varemail);
console.log(window.varmobile);
console.log(window.varlocation);
}
函数function2(){
console.log(window.name);
console.log(window.varemail);
console.log(window.varmobile);
console.log(window.varlocation);
“名称”:window.name,
“电子邮件”:window.varemail,
“mobile”:window.varmobile,
“位置”:window.varlocation,
“工作空间”:$scope.workingSpace.category,
“没有人”:$scope.noOfPerson,
“加入日期”:$scope.startDate,
“工作时间”:工作时间,
“期间”:$scope.period,
“multipleDays”:$scope.multipleDays,
}
>
>form.blade.php文件
>我以这种格式获取php文件中的值:这是一个
>我如何接受姓名和移动字段`
````
您的电子邮件
您的手机
````
能否显示保存$scope.data对象的值的代码…我猜需要检查scope数据上的值。因为如果您尝试以下代码,它将按预期工作-函数function1(){window.name='a';window.varemail='b';window.varmobile='c';window.varlocation='d';}函数function2(){console.log(window.name)console.log(window.varemail)}您如何尝试访问该变量?请检查更新的代码。我不能理解这个问题。因为,全局变量可以在函数1中访问。为什么,函数2中只定义了名称?
<!-- language: lang-js -->
`````
<!--'Postspace.js' File-->
function function1() {
window.name = $scope.data.name;
// window.email = 'c@g.com';
window.varemail = $scope.data.email;
window.varmobile = $scope.data.mobile;
window.varlocation = $scope.data.location;
console.log(window.name);
console.log(window.varemail);
console.log(window.varmobile);
console.log(window.varlocation);
}
function function2() {
console.log(window.name);
console.log(window.varemail);
console.log(window.varmobile);
console.log(window.varlocation);
'name': window.name,
'email': window.varemail,
'mobile': window.varmobile,
'location': window.varlocation,
'working_space': $scope.workingSpace.category,
'no_of_persons': $scope.noOfPerson,
'joining_date': $scope.startDate,
'working_hours': workingHours,
'period': $scope.period,
'multipleDays': $scope.multipleDays,
}
>
> form.blade.php file
> I am taking the values in the php file in this format: This is an example of
> how I am accepting the name and the mobile field. `
````
<div class="col-lg-10 col-md-10 form-group" ng-class="{'has-error': LoginForm.fullEmail.$invalid && LoginForm.fullEmail.$touched}">
<p class="form-label ">Your Email</p>
<div class="row ">
<div class="col-lg-8 col-md-8"> <input type="email" ng-model="data.email" name="fullEmail" class="form-control " required placeholder="EMAIL" ng-model-options="{debounce: 200}"></div>
</div>
</div>
<div class="col-md-10 form-group" ng-class="{'has-error': LoginForm.fullmobile.$invalid && LoginForm.fullmobile.$touched}">
<p class="form-label">Your Mobile</p>
<div class="row">
<div class="col-md-8"><input type="text" ng-model="data.mobile" name="fullmobile" class=" form-control" required placeholder="MOBILE" ng-pattern="/^[6-9]{1}[0-9]{9}$/"></div>
</div>
</div>
````