最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ReferenceError: function is not defined on the onclick function - Stack Overflow

programmeradmin0浏览0评论

I get a "ReferenceError: punt is not defined" - everything seems to be right and I can't identify the mistake.

Here is the related code:

<script src="../Scripts/jquery-1.9.1.min.js" type="text/javascript">

 function punt(rowIndex, Name, actionType) {
            alert("hello");
        }

</script>

and inside the ItemTemplate in the Repeater I have:

<input type="image" style="border-width:0" src='<%=ResolveUrl("~/css/images/icon_update.png") %>'  
                                         alt="Update Reviewer List" tabindex="0" title="Update Reviewer List"  
                                         onclick="punt(<%#Container.ItemIndex%>,  
                                                      '<%#HttpUtility.HtmlEncode((string)DataBinder.Eval(Container.DataItem, "Name"))%>', 
                                                      'Update');
                        return false;" />  

I get a "ReferenceError: punt is not defined" - everything seems to be right and I can't identify the mistake.

Here is the related code:

<script src="../Scripts/jquery-1.9.1.min.js" type="text/javascript">

 function punt(rowIndex, Name, actionType) {
            alert("hello");
        }

</script>

and inside the ItemTemplate in the Repeater I have:

<input type="image" style="border-width:0" src='<%=ResolveUrl("~/css/images/icon_update.png") %>'  
                                         alt="Update Reviewer List" tabindex="0" title="Update Reviewer List"  
                                         onclick="punt(<%#Container.ItemIndex%>,  
                                                      '<%#HttpUtility.HtmlEncode((string)DataBinder.Eval(Container.DataItem, "Name"))%>', 
                                                      'Update');
                        return false;" />  
Share edited Mar 27, 2013 at 19:34 Aleksandr M 24.4k13 gold badges74 silver badges146 bronze badges asked Mar 27, 2013 at 19:33 user1216456user1216456 0
Add a ment  | 

2 Answers 2

Reset to default 7

You can't bine a script include and inline javascript.

<script src="../Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
<script>
    function punt(rowIndex, Name, actionType) {
        alert("hello");
    }
</script>

Your script tag which includes the external script should be separate from your script tag where you define your new function, i.e.:

<!-- first script tag -->
<script src="jquery"></script>

<!-- second script tag -->
<script>
 // punt function
</script>
发布评论

评论列表(0)

  1. 暂无评论