JavaScript: change function(this) to function(this.id)
JavaScript: change function(this) to function(this.id)
我有这个javascript
函数打开kcfinder文件管理器url的文本框。
JS:
<script type="text/javascript">
function openKCFinder(field) {
window.KCFinder = {
callBack: function(url) {
field.value = url;
window.KCFinder = null;
}
};
window.open("http://localhost/cms/kc/browse.php?type=video&dir=files/public", "kcfinder_textbox",
"status=0, toolbar=0, location=0, menubar=0, directories=0, " +
"resizable=1, scrollbars=0, width=800, height=600"
);
}
</script>
HTML: <input id="video" onclick="openKCFinder(this)" class="form-control" type="text" name="video" placeholder="add video"> // i need to change openKCFinder(this.id)
<input id="audio" onclick="openKCFinder(this)" class="form-control" type="text" name="video" placeholder="add video"> // i need to change openKCFinder(this.id)
现在我需要将(this)
更改为(this.id)
以更改打开url
的type
。即:如果textbox/input id="video"
则type=video
或如果textbox/input id="audio"
,则type=audio
。
如何根据我的需要改变这个功能?
DEMO Kcfinder文本框你可以这样做:
<script type="text/javascript">
function openKCFinder(field) {
window.KCFinder = {
callBack: function(url) {
field.value = url;
window.KCFinder = null;
}
};
if (field.id === 'video') {
window.open("http://localhost/cms/kc/browse.php?type=video&dir=files/public", "kcfinder_textbox",
"status=0, toolbar=0, location=0, menubar=0, directories=0, " +
"resizable=1, scrollbars=0, width=800, height=600"
);
}
else if (field.id === 'audio') {
// open something else
}
else {
// handle something unknown
}
}
</script>
如果你对id很确定,你也可以使用
window.open("http://localhost/cms/kc/browse.php?type=" + field.id + "&dir=files/public", "kcfinder_textbox",
"status=0, toolbar=0, location=0, menubar=0, directories=0, " +
"resizable=1, scrollbars=0, width=800, height=600"
);
您可能还会对MDN的HTMLInputElement文档感兴趣,该文档描述了field
中this
的属性。
相关文章:
- this内部的值返回this.each(function(){})
- This.props.dispatch not a function - React-Redux
- jQuery $(this) inside function
- 重复“;function(){}.调用(this)"在Uglified JS中
- Javascript get "this" class with onClick function
- 用(function(){…}).call(this)包装文件,而用简单的()包装调用
- Function.length和this.length不一样.为什么
- jQuery: addClass and click function for this class
- 函数(){}.bind(this) 和 angular.bind(this, function() {}) 之间的区别
- Advantage of (function() {/*...*/}).call(this);
- this.function 和 this.function() 之间的区别
- 为什么使用 (function(){}).call(this);.
- this.function不是函数错误,但函数存在
- TypeError:调用Function.protype.method()时,this.prototype未定义
- undefined is not a function when evaluating 'this.batman
- Javascript setTimeout function with 'this'
- this.text Function
- 如何理解“{ fun: function.bind(this) }”
- 我如何在this.function.bind(this)中替换任何数值作为参数
- 为什么是全球性的"this.function";如果没有";这个"