Jquery-Mobile:如何从html调用外部Java脚本函数 [英] Jquery-Mobile: How to call the external java script function from html

查看:132
本文介绍了Jquery-Mobile:如何从html调用外部Java脚本函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JQM的新手.我想从html调用外部Java脚本函数.为此,我在外部标签中包括了这样的外部javascript文件.

I am new to JQM. I want to call the external java script function from the html. For this i am including external javascript file in head tag like this.

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

我正在这样调用外部JS函数.在这里,我收到了类似scipt标签的无效位置之类的错误.在select标签中更改数据时如何调用外部JS函数?请任何人可以帮助我

I am calling external JS function like this. Here i am getting the error like this Invalid location of scipt tag. How to call the external JS function when change the data in select tag? 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>

推荐答案

您需要注意不要将脚本标签放在Smamatti提到的无效位置.您还应该将脚本标记加载到文档的末尾,或者结合文档加载功能加载到文档的开头.原因是您不希望javascript代码在没有html标记的情况下显示在您拥有的位置,所以该脚本如何期望在尚不存在的东西上运行?

You need to be careful of not putting script tags in invalid locations as metioned by 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?

这篇关于Jquery-Mobile:如何从html调用外部Java脚本函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆