繁体   English   中英

Javascript:尝试访问 window.variable 但即使在初始化后它仍然未定义

[英]Javascript: Trying to access window.variable but it stays undefined even after initialising

我在 function 1 中初始化了 4 个全局变量,并且还为函数赋值。 当我尝试访问下一个 function 中的变量时,只能访问第一个变量。 所有其他都是未定义的。

当用户填写基本表单信息时调用 Function1。 然后他被重定向到高级表格。 填满 forms 后,数据将存储在数据库中。

请提供一些解决方案。

<!-- 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>

````











您能否显示保存 $scope.data object 值的代码...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM