开发者

Javascript Script Error: Object Expected

I have a scriptlet in the ASPX page as below. When I browse to this page, the script debugger appears saying "Micosoft JScript runtime error: Object expected". I marked line with //<--error here. I removed everything and only left $(function(){}); It still complained about Object Expected. Do you know why? Thanks.

<fieldset>
    <button id="Case5" name = "Case5" class="wizard" title="click here to select the case">
    Case 5 - AAA </button><br />
    <button id="Case6" name = "Case6" class="wizard" title="click here to select the case">
    Case 6 - BBB </button><br />
</fieldset>

<script language="jav开发者_运维知识库ascript" type="text/javascript">
$(function () { //<--error here
    (":button").click(function () {
        appendSelection(this);
    });
});

function appendSelection(btn) {
    //ToDo: append the selected value to the hyperlink

    var caseNumber = btn.id;
    switch (caseNumber) {
       ....
    }
}

In the Site.Master the script libraries are

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/external/jquery.bgiframe-2.1.1.js" type="text/javascript"></script>


<script src="<%: Url.Content("~/Scripts/ui/jquery.ui.datepicker.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/datetimepicker_css.js") %>" type="text/javascript" ></script>
<script src="<%: Url.Content("~/Scripts/lang/calendar-en.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/json2.js") %>" type="text/javascript"></script>
<script type="text/javascript">var appRoot =  '<%:Url.Content("~/")%>'</script>
<script src="<%: Url.Content("~/Scripts/MyApp.js") %>" type="text/javascript"></script>


(":button").click(function () {

should be

$(":button").click(function () {
^---missing $


I think your issue is that you have a minor issue in your javascript and need to use the '$' to invoke jQuery in your selector.

This:

(":button").click(function () {
    appendSelection(this);
});

Needs to use jQuery for the selector as this:

$(":button").click(function () {
    appendSelection(this);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜