对象< object>没有方法"methodeX" [英] Object <object> has no method 'methodeX'
本文介绍了对象< object>没有方法"methodeX"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在chrome中出现错误:
i get an error in chrome:
未捕获的TypeError:对象s1A没有方法'applyToSelection'
Uncaught TypeError: Object s1A has no method 'applyToSelection'
在Firefox(萤火虫)中,我得到了:
in Firefox(firebug) i get this:
TypeError:val.applyToSelection不是函数
TypeError: val.applyToSelection is not a function
我使用rangy-core和rangy-cssclassappliere
i use the rangy-core and the rangy-cssclassappliere
我的代码:
<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>
如果有ID,请执行以下操作:
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
推荐答案
我建议将应用程序存储在对象中,其中每个属性名称都对应于一个输入值:
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();
}
这篇关于对象< object>没有方法"methodeX"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文