Javascript 如何在Framework7中使用JS?

Javascript 如何在Framework7中使用JS?,javascript,html,html-framework-7,Javascript,Html,Html Framework 7,我使用创建了一个应用程序。现在我尝试在我的页面内容中执行javascript,但它没有执行 <div class="pages"> <div class="page close-panel" data-page="item"> <div class="page-content"> <div class="content-block-title">Title</div> <script ty

我使用创建了一个应用程序。现在我尝试在我的
页面内容中执行
javascript
,但它没有执行

<div class="pages">
<div class="page  close-panel" data-page="item">
    <div class="page-content">
        <div class="content-block-title">Title</div>
        <script type="text/javascript">
          alert("testoutput"); // no alert
          console.log("TEST"); // no log
        </script>
    </div>
</div>
    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>

标题
警报(“测试输出”);//没有警报
console.log(“测试”);//无日志

    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>
如何运行此javascript代码

    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>
更新

    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>

该页面是从其他HTML页面加载的

如果您在index.html文件中编写了任何javascript代码,请将该代码放入

    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>

警报(“测试输出”);//没有警报
console.log(“测试”);//无日志
像这样,这是在index.html文件中定义的
或者,如果您想为某个特定的html文件编写JS代码,
你喜欢这样吗
标题
警报(“测试输出”);//没有警报
console.log(“测试”);//无日志

在此之前,我从未听说过Framework7,但在看了文档之后,我不相信您能够以这种方式使用Javascript

    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>
对于JS事件,您似乎必须在Framework7构造函数中限定事件的范围:

    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>
var myApp = new Framework7();

var $$ = Dom7;

$$('.alert-text').on('click', function () {
    myApp.alert('Here goes alert text');
});
当然,上面的示例直接取自F7文档,并且依赖于单击事件,但是您可以将警报事件作为
myApp
的一种方法来尝试,看看它是否适合您。

使用回调(onPageInit)来执行代码

    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>
var myApp = new Framework7();

//Add callback function that will be executed when Page with data-page="about" attribute will be initialized
myApp.onPageInit('dashboard', function (page) {
    console.log('dashboard page initialized');
    console.log(page);
});

// Option 2. Using live 'page:init' event handlers for each page (not recommended)
$$(document).on('page:init', '.page[data-page="dashboard"]', function (e) {
    console.log('dashboard loaded with page:init');
    createGraph();
});
上面这句话对我很管用。。尽管跟踪没有起作用

    <head> 
      <script>
         alert("testoutput"); // no alert
         console.log("TEST"); // no log
      </script>
    </head> like this, which is defined in index.html file 

Or ,if you want write JS code for some particular html file ,

Do like this

 <div class="page  close-panel" data-page="item">
 <div class="page-content">
    <div class="content-block-title">Title</div>
</div>
    <script>
      alert("testoutput"); // no alert
      console.log("TEST"); // no log
    </script>
 </div>
myApp.onPageInit('dashboard', function (page) {
    console.log('dashboard page initialized');
    console.log(page);
});

在我的例子中,你在哪里定义页面方法,例如,我不喜欢我必须将所有不同的页面脚本和方法放在app.js下,这样会导致文件变大和混乱。我应该将逻辑划分为不同的“.js”文件吗?