jquery+json實現動態商品內容展示的方法_jquery
本文實例講述了jquery+json實現動態商品內容展示的方法。分享給大家參考,具體如下:
<!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" xml:lang="zh" lang="zh" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <mce:script type="text/javascript" src="jquery-1.4.4.min.js" mce_src="jquery-1.4.4.min.js"></mce:script> <title>Example | xHTML1.0</title> </head> <mce:style><!-- div{width:50px;height:50px;float:left;margin:10px; text-align:center;} .a{font-size:50px;float:left; cursor:pointer;} .b{font-size:50px;background-color:yellow;float:left; cursor:pointer;} .border{border:2px solid;} .bb{} --></mce:style><style mce_bogus="1">div{width:50px;height:50px;float:left;margin:10px; text-align:center;} .a{font-size:50px;float:left; cursor:pointer;} .b{font-size:50px;background-color:yellow;float:left; cursor:pointer;} .border{border:2px solid;} .bb{}</style> <mce:script type="text/javascript"><!-- $(function () { var _json = {"red":{"small":"10","middle":"15","large":"20","max_large":"25"},"blue":{"small":"33","middle":"35","large":"9","max_large":"30"},"green":{"small":"34","middle":"30","large":"19","max_large":"3"},"orange":{"small":"9","middle":"15","large":"29","max_large":"18"}}; var _color_value; var _size_value; var _store_value; $("#select_color div").click(function () { $("#select_color div").attr("class","/bb"); $(this).attr("class","border"); _color_value = $(this).attr("date-value"); change_span_value() }); $("#select_size div").click(function () { $("#select_size div").attr("class","a"); $(this).attr("class","b"); _size_value = $(this).attr("date-value"); change_span_value() }); function change_span_value() { var _value = _json[_color_value][_size_value]; if (_value != undefined) { $("#span_store").text(_value+"件"); } } }); // --></mce:script> <body> <div style="width:100%;margin:10px;" id="select_color"> <div style="background-color:red;cursor:pointer;" mce_style="background-color:red;cursor:pointer;" date-value="red">Red</div> <div style="background-color:blue;cursor:pointer;" mce_style="background-color:blue;cursor:pointer;" date-value="blue">Blue</div> <div style="background-color:green;cursor:pointer;" mce_style="background-color:green;cursor:pointer;" date-value="green">Green</div> <div style="background-color:orange;cursor:pointer;" mce_style="background-color:orange;cursor:pointer;" date-value="orange">Orange</div> </div> <div style="width:100%;margin:10px;" id="select_size"> <div class="a" date-value="small">S</div> <div class="b" date-value="middle">M</div> <div class="a" date-value="large">L</div> <div class="a" date-value="max_large">XL</div> </div> <div style="width:100%;margin:10px;text-align:left;" id="select_store"> 库存:(<span id="span_store">1000件</span>) </div> <div style="border:2px solid;width:100px;height:100px;background-color:gray"></div> </body> </html>
更多關於jQuery操作json相關內容有興趣的讀者可查看本站專題:《jQuery操作json資料技巧總結》
希望本文所述對大家jQuery程式設計有所幫助。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

在建立虛擬機器時,系統會要求您選擇磁碟類型,您可以選擇固定磁碟或動態磁碟。如果您選擇了固定磁碟,後來意識到需要動態磁碟,或者相反,該怎麼辦?好!你可以把一種轉換成另一種。在這篇文章中,我們將看到如何將VirtualBox固定磁碟轉換為動態磁碟,反之亦然。動態磁碟是一種虛擬硬碟,它最初具有較小的大小,隨著您在虛擬機器中儲存數據,其大小會相應增長。動態磁碟在節省儲存空間方面非常高效,因為它們只佔用所需的主機儲存空間。然而,隨著磁碟容量的擴展,可能會稍微影響電腦的效能。固定磁碟和動態磁碟是虛擬機器中常用的

PHP數組轉JSON的效能最佳化方法包括:使用JSON擴充和json_encode()函數;新增JSON_UNESCAPED_UNICODE選項以避免字元轉義;使用緩衝區提高循環編碼效能;快取JSON編碼結果;考慮使用第三方JSON編碼庫。

Jackson庫中的註解可控制JSON序列化和反序列化:序列化:@JsonIgnore:忽略屬性@JsonProperty:指定名稱@JsonGetter:使用獲取方法@JsonSetter:使用設定方法反序列化:@JsonIgnoreProperties:忽略屬性@ JsonProperty:指定名稱@JsonCreator:使用建構子@JsonDeserialize:自訂邏輯

深入了解PHP:JSONUnicode轉中文的實作方法在開發中,我們經常會遇到需要處理JSON資料的情況,而JSON中的Unicode編碼在一些場景下會為我們帶來一些問題,特別是當需要將Unicode編碼轉換為中文字元時。在PHP中,有一些方法可以幫助我們實現這個轉換過程,以下將介紹常用的方法,並提供具體的程式碼範例。首先,讓我們先來了解一下JSON中Un

PHP陣列可透過json_encode()函數轉換為JSON字串(例如:$json=json_encode($array);),反之亦可用json_decode()函數從JSON轉換為陣列($array=json_decode($json);) 。其他技巧還包括:避免深度轉換、指定自訂選項以及使用第三方程式庫。

如何判斷jQuery元素是否具有特定屬性?在使用jQuery操作DOM元素時,常會遇到需要判斷元素是否具有某個特定屬性的情況。在這種情況下,我們可以藉助jQuery提供的方法來輕鬆實現這項功能。以下將介紹兩種常用的方法來判斷一個jQuery元素是否具有特定屬性,並附上具體的程式碼範例。方法一:使用attr()方法和typeof運算子//判斷元素是否具有特定屬

PHP提供了以下函數來處理JSON資料:解析JSON資料:使用json_decode()將JSON字串轉換為PHP數組。建立JSON資料:使用json_encode()將PHP陣列或物件轉換為JSON字串。取得JSON資料的特定值:使用PHP數組函數存取特定值,例如鍵值對或陣列元素。

JSON(JavaScriptObjectNotation)是一種輕量級的資料交換格式,通常用於Web應用程式之間的資料交換。在處理JSON資料時,我們經常會遇到Unicode編碼的中文字元(例如"u4e2du6587"),需要將其轉換為可讀的中文字元。在PHP中,我們可以透過一些簡單的方法來實現這個轉換。接下來,我們將詳細介紹如何將JSONUnico
