简体   繁体   English

Jquery-Mobile:如何从html调用外部Java脚本函数

[英]Jquery-Mobile: How to call the external java script function from html

I am new to JQM. 我是JQM的新手。 I want to call the external java script function from the html. 我想从html调用外部Java脚本函数。 For this i am including external javascript file in head tag like this. 为此,我在外部标签中包括了这样的外部javascript文件。

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Single page template</title>
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" type="text/css">
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
  <script type="text/javascript" src="food_exercise.js"></script>
  <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>

I am calling external JS function like this. 我正在这样调用外部JS函数。 Here i am getting the error like this Invalid location of scipt tag. 在这里,我收到类似scipt标签无效位置的错误。 How to call the external JS function when change the data in select tag? 更改选择标记中的数据时如何调用外部JS函数? please can anybody help me 请任何人可以帮助我

<div data-role="content">
  <div>
    <select onchange="set_FRE(this,Item_Activity,Qty_Time)" size="1" name="choice">
      <option value="" selected="selected">SELECT Food/Exercise</option>
      <script type="text/javascript">
        setChoice(this);
      </script>
    </select>
    <select name="Item_Activity" size="1" disabled="disabled" onchange="set_item_activity(this,Qty_Time)"></select>
    <select name="Qty_Time" size="1" disabled="disabled" onchange="print_IE_QT(Item_Activity,this)"></select>
  </div>
</div>

You need to be careful of not putting script tags in invalid locations as metioned by Smamatti. 您需要注意不要将脚本标记放在Smamatti提到的无效位置。 You should also, either load your script tags at the end of your document, or in the head of your document combined with a document load function. 您还应该在文档的末尾或与文档加载功能一起在文档的开头加载脚本标签。 The reason for that is you don't want your javascript code to exectue where you have it as the html tag isn't built yet, so how can the script expect to run on something that doesn't yet exist? 这样做的原因是您不希望javascript代码在没有html标签的情况下显示在您拥有它的位置,所以该脚本如何期望在尚不存在的东西上运行?

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

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