|
|
Postitatud 19.08.2015 21:09:49
|
|
|

Kuna see oli esimene kord, kui ma seda efekti tegin, tegin seda aeglaselt ja avastasin, et olin kirjutanud palju korduvat koodi.
Praegu pole aega optimeerimiseks, lepime sellega ja lõpuks lisame tihendatud paketi, sealhulgas andmebaasiskripti.
Lisaks on lisatud provintsi ja omavalitsuse sidumiskood, mis on kirjutatud puhtas js-is
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PlaceInfo.aspx.cs" Inherits="AjaxDemo.PlaceInfo" %>
- <!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">
- <title></title>
- <scrip去掉t src="scrip去掉ts/jquery-1.4.1.min.js" type="text/javascrip去掉t"></scrip去掉t>
- <scrip去掉t type="text/javascrip去掉t">
- //省方法
- function sheng() {
- var $sheng = $("#sheng option:selected").val();
- $.ajax({
- url: "ajax3.aspx",
- type: "get",
- data: "test=x&sheng=" + $sheng,
- success: function (mesg) {
- $("#shi").empty();
- $("#shi").append(mesg);
- $("#shi option:eq(0)").attr("selected", "selected");
- var num = $("#shi option").length;
- if (num > 1) {
- $("#shi").show();
- } else {
- $("#shi").hide();
- }
- shi();
- }
- });
- };
- //市方法
- function shi() {
- var $shi = $("#shi option:selected").val();
- $.ajax({
- url: "ajax3.aspx",
- type: "get",
- data: "test=x&sheng=" + $shi,
- success: function (mesg) {
- $("#xian").empty();
- $("#xian").append(mesg);
- $("#xian option:eq(0)").attr("selected", "selected");
- }
- });
- }
- $(function () {
- $.ajax({
- url: "ajax3.aspx",
- type: "get",
- data: "",
- success: function (mesg) {
- $("#sheng").append(mesg);
- $("#sheng option:eq(0)").attr("selected", "selected");
- sheng();
-
- }
- });
- /**测试按钮**/
- $(":button").click(function () {
- var $a = $("#sheng option:selected").val();
- alert($a);
- });
- //选中省
- $("#sheng").change(function () {
- sheng();
- });
- //选中市
- $("#shi").change(function () {
- shi();
- });
- });
- </scrip去掉t>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <select id="sheng"></select>
- <select id="shi"></select>
- <select id="xian"></select>
- <input type="button" value="test" />
- </div>
- </form>
- </body>
- </html>
Kopeeri kood
AjaxDemo.rar
(196.62 KB, Allalaadimiste arv: 4)
|
Eelmine:Arvuti kõvaketta C5 hoiatus, mida tehaJärgmine:jquery mitmed üldteadaolevad punktid
|