我有一个链接,单击链接时我想将标志变量的值设置为 1。这可能吗?喜欢
<a id='ctr' href='#' onclick='flag=1'> Hello </a>
以及如何在同一行上编写 onclick 事件的函数,例如代替
<a id='ctr' href='#' onclick='call_this();'> Hello </a>
function call_this(){
flag=1;
}
我可以在 onclick 行本身中有 call_this 函数吗?
编辑2
现在我有这样的代码。在 onclick 事件中,该值正确存储在 $selectedId 中。但是当我尝试在 url 中传递该值时,我没有得到正确的值。传递了 for 循环中的最后一个值。
<script type="text/javascript">
$(document).ready(function(){
<?php foreach ($Forms as $r): ?>
$("<a id='<?php echo $ctr['Form']['id'];?> href='#' onclick='flag=1'> Hello </a>").appendTo("#header").click(function(){
<?php $selectedId=$r['Form']['id'];?>
alert("selId: "+<?php echo $selectedId;?>);//here the selected value is echoed
});
</script>
<a href="http://localhost/Example/new/export?height=220&width=350&id=<?php echo $selectedId;?>" class="thickbox button" title= "Export" >Export</a>
这里 id 作为 4 传递,这是 php for 循环中的最后一个值。