0

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


How to remove touchevent in js?

I'm trying to remove touchevent after the first touch.
I've tried the next code, but it did not work:

ourCanvas.addEventListener("touchstart", function(){
    evt.preventDefault();
    startGame();
    ourGameCanvas.removeEventListener("touchstart");
}, false);`
4

1 に答える 1

0

各プロパティ名が入力値に対応するオブジェクトにアプライヤーを格納することをお勧めします。

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

function dosome(el) {
    var val = el.value;
    appliers[val].applyToSelection();
}
于 2012-12-02T22:43:21.467 に答える