Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/09/2013, 21:32
rascabuchitos
 
Fecha de Ingreso: abril-2011
Ubicación: Peru
Mensajes: 486
Antigüedad: 13 años, 1 mes
Puntos: 9
sacar y anexar js a html

hola amigos
tengo este codigo dentro del body

Código HTML:
Ver original
  1.   <div class='liveExample'>
  2.    
  3.     <form data-bind="submit:addItem">
  4.         Add item: <input type="text" data-bind='value:itemToAdd, valueUpdate: "afterkeydown"' />
  5.         <button type="submit" data-bind="enable: itemToAdd().length > 0">Add</button>
  6.     </form>
  7.      
  8.     <p>Your values:</p>
  9.     <select multiple="multiple" height="5" data-bind="options:allItems, selectedOptions:selectedItems"> </select>
  10.      
  11.     <div>
  12.         <button data-bind="click: removeSelected, enable: selectedItems().length > 0">Remove</button>
  13.         <button data-bind="click: sortItems, enable: allItems().length > 1">Sort</button>
  14.     </div>
  15.    
  16. </div>
  17.  
  18.  
  19.  
  20. <script type='text/javascript'>//<![CDATA[
  21.  
  22. var BetterListModel = function () {
  23.    this.itemToAdd = ko.observable("");
  24.    this.allItems = ko.observableArray(["Fries", "Eggs Benedict", "Ham", "Cheese"]); // Initial items
  25.    this.selectedItems = ko.observableArray(["Ham"]);                                // Initial selection
  26.  
  27.    this.addItem = function () {
  28.        if ((this.itemToAdd() != "") && (this.allItems.indexOf(this.itemToAdd()) < 0)) // Prevent blanks and duplicates
  29.            this.allItems.push(this.itemToAdd());
  30.        this.itemToAdd(""); // Clear the text box
  31.    };
  32.  
  33.    this.removeSelected = function () {
  34.        this.allItems.removeAll(this.selectedItems());
  35.        this.selectedItems([]); // Clear selection
  36.    };
  37.  
  38.    this.sortItems = function() {
  39.        this.allItems.sort();
  40.    };
  41. };
  42.  
  43. ko.applyBindings(new BetterListModel());
  44. //]]>  
  45.  
  46.  
  47.  
  48. </body>


mi consulta es:
como puedo sacar el js en un archivo aparte y llamarlo por medio de src
sin que afecte el funcionamiento, ya que itemToAdd
es un termino comun dentro de los div como del script


gracias