简体   繁体   中英

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

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>

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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