Mit*_*ath 3 javascript jquery jquery-plugins
我有一个jQuery插件.我想在我的jQuery插件中添加try catch块以进行异常处理.
我的插件
$(document).ready(function(){
$('.requiredclass').keyup(function() {
$(this).pluginMethod();
});
});
(function($) { //i Want try catch block for this part
// jQuery plugin definition
$.fn.pluginMethod = function(e) {
return this.each(function() {
var $this = $.this;
var som= $this.val();
//My Code goes here
});
};
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
现在,如果我想添加try catch块,那么插件的外观如何?在jquery函数的情况下我们做这样的事情
功能
function myFunction() {
//varible declarations
try {
//Code goes here
}
catch(err) { //We can also throw from try block and catch it here
alert("err");
}
finally {
//code for finally block
}
}
Run Code Online (Sandbox Code Playgroud)
现在这是我们在函数的情况下知道的格式.但是如果我想在插件中添加异常处理,那么格式是什么?在从插件(function($) {的插件开始,然后有$.fn.pluginMethod = function(e) {后跟
return this.each(function() {`. So where to start the try block and stop it,where to put catch block.Can any one suggest me the format.
Run Code Online (Sandbox Code Playgroud)
如果有任何人对理解这个问题有任何疑问,请告诉我,我会尝试更详细地解释.
我不认为我真的得到你的问题.你需要更清楚.
但这是你想要的吗?
$(document).ready(function(){
$('.requiredclass').keyup(function() {
$(this).pluginMethod();
});
});
try {
(function($) {
//jQuery plugin definition
$.fn.pluginMethod = function(e) {
return this.each(function() {
var $this = $.this;
var som= $this.val();
//your Code goes here
});
};
})(jQuery);
} catch(err) { //We can also throw from try block and catch it here
alert("err");
} finally {
//code for finally block
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14725 次 |
| 最近记录: |