<input type="checkbox" id = "has_sidebar" name="cb" value="" onclick="result=$(this).attr('value', this.checked ? 1 : 0); alert('my result : 'result.context.value);" >
RESULT.CONTEXT.VALUE
具有该复选框(0
或1
)的值。的Perl的javascript/jquery的 - 变量传递从JavaScript/jquery的到perl
如何在perl变量中赋值?
这是代码。
<%class>
use JSON;
use URI::Escape;
has 'data';
has 'cb' => (isa => 'Array');
</%class>
<%init>
my $args = eval {
return from_json(uri_unescape($.data), { ascii => 1});
};
$m->redirect('/login') unless $USER && $USER->{'logged_in'};
$args->{'authors'} = [] unless $args->{'authors'} && ref($args->{'authors'}) eq 'ARRAY';
</%init>
<li class="header">
<p>
Authors
       
       
show sidebar
</p>
</li>
% my @author_box =();
% foreach my $a (sort { $a->{'last_name'} cmp $b->{'last_name'} || $a->{'first_name'} cmp $b->{'first_name'} } @{$args->{'authors'}}) {
<li>
<p>
<a href="javascript:void(0)" onclick="remove_author(<% $a->{'id'} %>);" class="right icon-small icon-delete-small"></a>
<% $a->{'last_name'} %>, <% $a->{'first_name'} %> (<% $a->{'initials'} %>)
    
    
<input type="checkbox" id = "has_sidebar" name="cb" value="" onclick="result=$(this).attr('value', this.checked ? 1 : 0); alert('id : <% $a->{'id'} %> - checked: ' + result.context.value);" >
</p>
</li>
% # put the value of the checkbox in array
<script type="text/javascript">
<% $.cb %> = result.context.value //this is not the RIGHT WAY!!!
var hsb = [];
hsb.push({ <% $a->{'id'} %>: <% $.cb %> });
</script>
% }
<li>
<p>
<input type="submit" value="Add" class="right" onclick="add_author();"/>
<input id="new_author" style="width:75%;" />
<input type="hidden" id="new_author_data" />
</p>
</li>
“在窗体中添加隐藏字段?” – 2012-05-30 23:34:35
链接到的代码不是Perl,它是某种带有perl嵌入的模板语言。你能告诉我们它是什么吗? – ysth
梅森2是一个模板框架。只需要知道**如何将一个javacript变量分配给一个perl变量**。谢谢 – mamesaye