2013-10-07 34 views
0

嗨,我是VS2010的新手,我正在ASP.NET中嘗試JavaScript。我曾嘗試引用我的示例腳本,但他們不工作,爲什麼?jQuery不能在VS2010中工作

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Member_supplier_details.WebForm1" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("button").click(function() { 
      $("div").animate({ left: '250px' }); 
     }); 
    }); 
</script> 
    <title>test</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <button>Start Animation</button> 
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p> 
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"> 
</div> 
    <!-- <input name="Qty" type="text" id="Text1" value="0" size="3" tabindex="2000" class="spinner" /> --> 
    </div> 
    </form> 
</body> 
</html> 
+3

「他們不工作」怎麼樣?你有什麼錯誤嗎? – doctorlove

+0

你的代碼工作在我身邊!這裏你確切的問題是什麼? –

+1

jQuery代碼沒有問題 - 請參閱這裏exact- http://jsfiddle.net/stackrahul/vQ4re/ – Manoj

回答

0

更改你的按鈕代碼。 becoz按鈕沒有類型提交,因此您的頁面submited。所以改變你的類型爲按鈕。

<button type="button">Start Animation</button> 
-1

按鈕和DIV他們沒有ID'。你需要在HTML標籤中給它們ID,然後在javascript中使用這些ID來做更改