Object <object> has no method 'methodeX'

我的未来我决定 提交于 2019-12-12 03:32:02

问题


i get an error in chrome:

Uncaught TypeError: Object s1A has no method 'applyToSelection'

in Firefox(firebug) i get this:

TypeError: val.applyToSelection is not a function

i use the rangy-core and the rangy-cssclassappliere

my Code:

<script type="text/javascript"> 
    window.onload = function() {    
    rangy.init();
      s1A = rangy.createCssClassApplier("css_1", true); 
    };

   //this is the Problem.
   function dosome (el) {
      var val = el.value;
      val.applyToSelection();
   }
</script>

<body>
  <button value="s1A" onclick="dosome(this);">test</button>
</body>

if id do this:

<script type="text/javascript"> 
    window.onload = function() {    
    rangy.init();
      s1A = rangy.createCssClassApplier("css_1", true); 
    };
   function s1() {
      s1A.applyToSelection();
   }
</script>

<body>
  <button onclick="s1();">test</button>
</body>

it works fine. But i need it for an option field and i want to get the value


回答1:


I suggest storing appliers in an object where each property name corresponds to an input value:

window.onload = function() {
    var appliers = {};
    rangy.init();
    appliers.s1A = rangy.createCssClassApplier("css_1", true); 
};

function dosome(el) {
    var val = el.value;
    appliers[val].applyToSelection();
}


来源:https://stackoverflow.com/questions/13669579/object-object-has-no-method-methodex

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