HTML5¼¼Êõ

js·â×°µÄÈý¼¶Áª¶¯²Ëµ¥(ʹÓÃʱֻÐèÒªÒ»ÐÐjs´úÂë) - ÃÎÒàÏþ

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-10-27 12:00 ÎÒÒªÆÀÂÛ( )

Ç°ÑÔ ÔÚʵ¼ÊµÄÏîÄ¿¿ª·¢ÖУ¬ÎÒÃǾ­³£ÐèÒªÈý¼¶Áª¶¯£¬±ÈÈçÊ¡ÊÐÇøµÄÑ¡Ôñ£¬ÉÌÆ·µÄÈý¼¶·ÖÀàµÄÑ¡ÔñµÈµÈ¡£ ¶øÍøÉÏÈ´ÕÒ²»µ½Ò»¸ö´úÂëÍêÕû¡¢¹¦ÄÜÇ¿´ó¡¢Ê¹Óüòµ¥µÄÈý¼¶Áª¶¯²Ëµ¥£¬´ó¶¼Ö»ÊǼòµ¥µÄ½²ÁËÒ»ÏÂʵÏÖ˼·¡£ ÏÂÃæ¾Í¸ø´ó¼Ò·ÖÏíÎÒÔÚ¹¤×÷Öзâ×°²¢ÔÚÏîÄ¿ÖÐʹÓõÄÈý¼¶¼¶

Ç°ÑÔ

ÔÚʵ¼ÊµÄÏîÄ¿¿ª·¢ÖУ¬ÎÒÃǾ­³£ÐèÒªÈý¼¶Áª¶¯£¬±ÈÈçÊ¡ÊÐÇøµÄÑ¡Ôñ£¬ÉÌÆ·µÄÈý¼¶·ÖÀàµÄÑ¡ÔñµÈµÈ¡£

¶øÍøÉÏÈ´ÕÒ²»µ½Ò»¸ö´úÂëÍêÕû¡¢¹¦ÄÜÇ¿´ó¡¢Ê¹Óüòµ¥µÄÈý¼¶Áª¶¯²Ëµ¥£¬´ó¶¼Ö»ÊǼòµ¥µÄ½²ÁËÒ»ÏÂʵÏÖ˼·¡£

ÏÂÃæ¾Í¸ø´ó¼Ò·ÖÏíÎÒÔÚ¹¤×÷Öзâ×°²¢ÔÚÏîÄ¿ÖÐʹÓõÄÈý¼¶¼¶Áª²Ù×÷´úÂ룬ÈçÓдíÎó»òÕß²»µ±µÄµØ·½»¶Ó­´ó¼ÒÖ¸Õý¡£

ÑÝʾЧ¹ûÔ¤ÀÀ£º

Èý¼¶Áª¶¯·â×°

Ô­Àí£º½«selec±êÇ©ÒÔ¼°Ïà¹ØµÄhtml´úÂëÓÃjsÊý×é¶ÔÏóµÄ·½Ê½½áºÏÔÚÒ»Æð¡£

jsÈçÏ£º

È«²¿js´úÂëÈçÏ£º

WJH_Category = { Category1ID: "wjh_category1_select", Category2ID: "wjh_category2_select", Category3ID: "wjh_category3_select", DataURL: "/Public/GetProductCategorys",Init: function (wrapID, category1, category2, category3, useEmpty, successCallBack) { WJH_Category.InitTag(wrapID, useEmpty); WJH_Category.InitData(category1, category2, category3, useEmpty, successCallBack); WJH_Category.category1Select(useEmpty); WJH_Category.category2Select(useEmpty); }, //³õʼ»¯±êÇ© InitTag: function (wrapID, useEmpty) { var tmpInit = ""; tmpInit += "<span>Ò»¼¶·ÖÀࣺ</span>"; if (useEmpty) { tmpInit += "<select><option value='0'>--ÇëÑ¡Ôñ--</option></select>"; } else { tmpInit += "<select></select>"; } tmpInit += "<span>¶þ¼¶·ÖÀࣺ</span>"; if (useEmpty) { tmpInit += "<select><option value='0'>--ÇëÑ¡Ôñ--</option></select>"; } else { tmpInit += "<select></select>"; } tmpInit += "<span>Èý¼¶·ÖÀࣺ</span>"; if (useEmpty) { tmpInit += "<select><option value='0'>--ÇëÑ¡Ôñ--</option></select>"; } else { tmpInit += "<select></select>"; } $("#" + wrapID + "").html(tmpInit); }, //³õʼ»¯Êý¾Ý--°üÀ¨ÐÞ¸Ä InitData: function (incategory1, incategory2, incategory3, useEmpty, successCallBack) { (incategory1 == 0) { $.get(WJH_Category.DataURL, {}, function (category1) { var firstcategory1Guid = category1[0].Value; (var i = 0; i < category1.length; i++) { var tmp_option = " <option value='" + category1[i].Value + "'>" + category1[i].Display + "</option>"; $("#" + WJH_Category.Category1ID + "").html($("#" + WJH_Category.Category1ID + "").html() + tmp_option); } if (useEmpty) { successCallBack(); return; } //³õʼ»¯¶þ¼¶·ÖÀà $.get(WJH_Category.DataURL, { pid: firstcategory1Guid }, function (category2) { var firstcategory2Guid = category2[0].Value; for (var i = 0; i < category2.length; i++) { var tmp_option = " <option value='" + category2[i].Value + "'>" + category2[i].Display + "</option>"; $("#" + WJH_Category.Category2ID + "").html($("#" + WJH_Category.Category2ID + "").html() + tmp_option); } //³õʼ»¯ÏØ $.get(WJH_Category.DataURL, { pid: firstcategory2Guid }, function (category3) { for (var i = 0; i < category3.length; i++) { var tmp_option = " <option value='" + category3[i].Value + "'>" + category3[i].Display + "</option>"; $("#" + WJH_Category.Category3ID + "").html($("#" + WJH_Category.Category3ID + "").html() + tmp_option); } successCallBack(); }, "json"); }, "json"); }, "json"); } { $.get(WJH_Category.DataURL, {}, function (category1) { (var i = 0; i < category1.length; i++) { var tmp_option = ""; if (category1[i].Value == incategory1) { tmp_option = " <option selected='selected' value='" + category1[i].Value + "'>" + category1[i].Display + "</option>"; } else { tmp_option = " <option value='" + category1[i].Value + "'>" + category1[i].Display + "</option>"; } $("#" + WJH_Category.Category1ID + "").html($("#" + WJH_Category.Category1ID + "").html() + tmp_option); } //³õʼ»¯¶þ¼¶·ÖÀà $.get(WJH_Category.DataURL, { pid: incategory1 }, function (category2) { for (var i = 0; i < category2.length; i++) { var tmp_option = ""; if (category2[i].Value == incategory2) { tmp_option = " <option selected='selected' value='" + category2[i].Value + "'>" + category2[i].Display + "</option>"; } else { tmp_option = " <option value='" + category2[i].Value + "'>" + category2[i].Display + "</option>"; } $("#" + WJH_Category.Category2ID + "").html($("#" + WJH_Category.Category2ID + "").html() + tmp_option); } //³õʼ»¯Èý¼¶·ÖÀà $.get(WJH_Category.DataURL, { pid: incategory2 }, function (category3) { for (var i = 0; i < category3.length; i++) { var tmp_option = ""; if (category3[i].Value == incategory3) { tmp_option = " <option selected='selected' value='" + category3[i].Value + "'>" + category3[i].Display + "</option>"; } else { tmp_option = " <option value='" + category3[i].Value + "'>" + category3[i].Display + "</option>"; } $("#" + WJH_Category.Category3ID + "").html($("#" + WJH_Category.Category3ID + "").html() + tmp_option); } successCallBack(); }, "json"); }); }); } }, //Ò»¼¶·ÖÀàchange category1Select: function (useEmpty) { $("#" + WJH_Category.Category1ID + "").change(function () { var optionHtml = ""; if (useEmpty) { optionHtml = "<option value='0'>--ÇëÑ¡Ôñ--</option>"; } $("#" + WJH_Category.Category2ID + "").html(optionHtml); $("#" + WJH_Category.Category3ID + "").html(optionHtml); var tmpSelectedcategory1 = $("#" + WJH_Category.Category1ID + " option:selected").val(); //³õʼ»¯¶þ¼¶·ÖÀà $.get(WJH_Category.DataURL, { pid: tmpSelectedcategory1 }, function (category2) { var firstcategory2Guid = category2[0].Value; for (var i = 0; i < category2.length; i++) { var tmp_option = " <option value='" + category2[i].Value + "'>" + category2[i].Display + "</option>"; $("#" + WJH_Category.Category2ID + "").html($("#" + WJH_Category.Category2ID + "").html() + tmp_option); } if (useEmpty) { return; } //³õʼ»¯Èý¼¶·ÖÀà $.get(WJH_Category.DataURL, { pid: firstcategory2Guid }, function (category3) { for (var i = 0; i < category3.length; i++) { var tmp_option = " <option value='" + category3[i].Value + "'>" + category3[i].Display + "</option>"; $("#" + WJH_Category.Category3ID + "").html($("#" + WJH_Category.Category3ID + "").html() + tmp_option); } }, "json"); }, "json"); }); }, //¶þ¼¶·ÖÀàchange category2Select: function (useEmpty) { $("#" + WJH_Category.Category2ID + "").change(function () { var optionHtml = ""; if (useEmpty) { optionHtml = "<option value='0'>--ÇëÑ¡Ôñ--</option>"; } $("#" + WJH_Category.Category3ID + "").html(optionHtml); var tmpSelectedcategory2 = $("#" + WJH_Category.Category2ID + " option:selected").val(); //³õʼ»¯Èý¼¶·ÖÀà $.get(WJH_Category.DataURL, { pid: tmpSelectedcategory2 }, function (category3) { for (var i = 0; i < category3.length; i++) { var tmp_option = " <option value='" + category3[i].Value + "'>" + category3[i].Display + "</option>"; $("#" + WJH_Category.Category3ID + "").html($("#" + WJH_Category.Category3ID + "").html() + tmp_option); } }, "json"); }); } };

View Code

 ºǫ́Êý¾Ý¸ñʽÈçÏÂ(¿É¸ù¾Ý×Ô¼ºµÄÐèÇó¸ü¸ÄÊý¾ÝÔ´)£º

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • JS×é¼þϵÁСª¡ª·ÖÏí×Ô¼º·â×°µÄBootstrapÊ÷ÐÎ×é¼þ£ºjqTree - ÀÁµÃ°²·Ö

    JS×é¼þϵÁСª¡ª·ÖÏí×Ô¼º·â×°µÄBootstrapÊ÷ÐÎ×é¼þ£ºjqTree - ÀÁµÃ°²·Ö

    2016-01-20 11:00

  • [×Ô¼º¶¯ÊÖÍæºÚ¿Æ¼¼] 1¡¢Ð¡ºÚ¿Æ¼¼¡ª¡ªÈçºÎ½«ÆÕͨµÄ¼Òµç¸ÄÔì³É¿ÉÒÔÓëÊÖ»úAppÁª¶¯µÄ¡°ÖÇÄÜÓ²¼þ¡± - beautifulz

    [×Ô¼º¶¯ÊÖÍæºÚ¿Æ¼¼] 1¡¢Ð¡ºÚ¿Æ¼¼¡ª¡ªÈçºÎ½«ÆÕͨµÄ¼Òµç¸ÄÔì³É¿ÉÒÔÓëÊÖ

    2015-11-16 19:40

ÍøÓѵãÆÀ
¹