我一直在玩AUTOLOADPerl创建我的访问器,我遇到了这种困惑(我已经搜索过google和perldoc).
我有这个代码:
package Class;
sub new {
..code for constructor here.
}
sub AUTOLOAD {
my $name= shift;
print $name;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我做类似的事情时:my $a=Class->new;自动加载子程序仍然执行,并打印Class=HASH(some weird number);
我以为AUTOLOAD只在有未定义的方法或子程序时运行?
我也是这样做的:
my $class = our $AUTOLOAD;
print $class #prints ::DESTROY
Run Code Online (Sandbox Code Playgroud)
当我DESTROY没有传递未定义的函数时,我认为这是$ AUTOLOAD的值,我是对的吗?
如果我有这样的事情:
%hash = {foo => 'bar', foo1=>'bar1',};
Run Code Online (Sandbox Code Playgroud)
要么
%hash = (foo => 'bar', foo1=>'bar1',);
Run Code Online (Sandbox Code Playgroud)
要么
$hash = {foo => 'bar', foo1=>'bar1',};
Run Code Online (Sandbox Code Playgroud)
要么
$hash = (foo => 'bar', foo1=>'bar1',);
Run Code Online (Sandbox Code Playgroud)
上述代码有何不同?以及如何访问他们的组件?
我不喜欢这里的东西,我只是在试验.
所以我试过了
#! usr/bin/perl
use warnings;
use strict;
use POSIX;
Run Code Online (Sandbox Code Playgroud)
我可以这样做:
my $point = bless {}, 'POSIX';
print $point->strftime("%A, %B %d, %Y", @time);
Run Code Online (Sandbox Code Playgroud)
试过那个它给出了错误.
我知道:
my %hash = {};
Run Code Online (Sandbox Code Playgroud)
得到一个匿名哈希,这个怎么样:
my %hash = %{some values}
Run Code Online (Sandbox Code Playgroud)
上面与此有什么不同?
my %hash = (some hash values);
Run Code Online (Sandbox Code Playgroud) $('.invoice_resend').hide();
$('.invoice_resend #update_paid').hide();
$('.invoice_send').hide();
Run Code Online (Sandbox Code Playgroud)
所以我有这样的代码上面,阶级invoice_resend是一个div,它被点击将被隐藏的按钮时,如上图所示,与#update_paid和.invoice_send也将被隐藏,留下我一个" 调整大小DIV "元素.
我想要的是,当隐藏所有其他元素时,.invoice_resend div将保持其高度或需要编辑的任何内容.
编辑:
好的,这是我的整个代码:
if (selected_tab == 0) { //Released tab
$('.invoice_resend').hide();
$('.invoice_send').show();
}
else if ( selected_tab == 1 ) { //Invoiced tab
$('.invoice_resend').show();
$('.invoice_resend #update_paid').show();
$('.invoice_send').hide();
}
else if ( selected_tab == 2 ) { //Paid tab
$('.invoice_resend').show();
$('.invoice_resend #update_paid').hide();
$('.invoice_send').hide();
}
else if ( selected_tab == 3 ) { //Pending tab
$('.invoice_resend').hide();
$('.invoice_resend #update_paid').hide();
$('.invoice_send').hide();
}
Run Code Online (Sandbox Code Playgroud)
似乎css.({visibility: 'hidden' or 'visible'})做了工作但产生了另一个问题.你看,我有几个标签,所以当我点击隐藏所有元素的最后一个标签时,它会变得不稳定,当我点击另一个标签时显示或隐藏随机元素.上面的代码是我的原始代码,我根据你的答案编辑了所有.css.
伙计我有2个问题,我认为这些问题在某种程度上与我有关.第一:
这两者有什么区别:
$(document).on('click','#someselector', function() {
//do something
});
Run Code Online (Sandbox Code Playgroud)vs这个
$('#selector')on('click', function(){
/do something
});
Run Code Online (Sandbox Code Playgroud)
有时两者都有效,有时则不然.
第2个问题:
我创建了一个jQuery UI这样的对话框:
function this_dialog(id) {
$("#div-id-for-the-dialog").dialog({
autoOpen : false,
modal : true,
draggable : false,
width : 400,
buttons : [{
id : id,
text : 'Ok'
},{
text : 'Cancel',
click : function () {
$("#div-id-for-the-dialog").dialog('close');
}
}]
});
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,id被传递给函数,许多人将调用此对话框并将唯一ID传递给它.然后,id将仅分配给Ok按钮.
所以当我调用此函数来加载一个唯一的对话框时:
add_section_complete_reopen_dialog('my-unique-dialog-id'); //passing the id
$('#div-id-for-the-dialog').html("I have a unique dialog now? ok?");
Run Code Online (Sandbox Code Playgroud)
当我用这段代码按ok时:
$(document).on('click','#my-unique-dialog-id', function () {
//Do …Run Code Online (Sandbox Code Playgroud)