如何从<a href="">到javascript函数

How to send the id of iterator from <a href=""> to javascript function

本文关键字:quot gt javascript 函数 lt href      更新时间:2023-09-26

我想通过链接搜索迭代器的id我试过了,但没有工作

我的链接就像

 <s:iterator  value="answerswerList" status="id">
 <a  class="link" href="javascript:countactu_Form('+"%{#id.index}"+')" >add Comment</a>
 <div id="Contactu-Form-%{#id.index}" >
   <s:textarea name="description" rows="5" cols="60" theme="simple" />
  </div>

我的功能就像

 function countactu_Form(id){
            alert("123456789");
            alert(id);
            $('#Contactu-Form-'+id).animate({
                height: 'toggle'
            },150, function() {
                // Animation complete.
            });
        }

请下次发布链接的"视图源"

应用@Umesh的建议并更改脚本以在更多浏览器中工作,请尝试

<a class="link" href="#" onclick="return countactu_Form('<s:property value="%{#id.index}"/>')">add Comment</a>

并更改功能以返回错误

function countactu_Form(id){
  $('#Contactu-Form-'+id).animate({
    height: 'toggle'
  },150, function() {
  // Animation complete.
  });
  return false;
}