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

雨燕双飞 提交于 2019-12-12 03:22:51

问题


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>

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>

回答1:


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?



来源:https://stackoverflow.com/questions/8501079/jquery-mobile-how-to-call-the-external-java-script-function-from-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!