我有一个带有静态函数的 PHP 类:
<? echo view::getUserSelector() ?>
哪个输出:
<div id="user_selector">
<div class="user">
<h1>Username1</h1>
<a href="javascript:selectUser(this);">select</a>
</div>
<div class="user">
<h1>Username2</h1>
<a href="javascript:selectUser(this);">select</a>
</div>
</div>
我需要做什么才能使这成为可能?:
<? echo view::getUserSelector(array('onSelect' => 'function() { alert(this.id); }')); ?>
- 如何“添加”
onSelect
-value 作为 的函数div#user_selector
? - 我如何“调用”
div#user_selector.onSelect()
参考this
为div#user_select
?
Javascript:
function selectUser(anchor) {
//remove all 'selected' classes from $user_selector child divs
//add 'selected' class to parent div.user of anchor
}