Sealyu

          --- 博客已遷移至: http://www.sealyu.com/blog

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

          An old problem with IE is that you can't set the name attribute on form elements in the DOM directly. Fortunately there is a workaround to this issue using IE's mergeAttributes method. By creating a temporary named element acceptable by IE's createElement method, you can merge the name attribute into the element you desire, allowing you to name or rename an element. An example demo follows.

          var setName = function(el, newName) {

          el = (typeof el === "string") ? document.getElementById(el) : el;

          el.name = newName;

          if (/*@cc_on!@*/0) { // Internet Explorer test (needs to be modified for IE8)

          el.mergeAttributes(document.createElement("<INPUT name='" + newName + "'/>"), false);

          }

          };

          In Mootools 1.2.1:

          var setName = function(elementId, newName) {

          var el = (!!elementId) ? $(elementId) : null;

          if (!elementId || !newName || !el) return;



          el.set({ "name" : newName });

          if (Browser.Engine.trident4 || Browser.Engine.trident5) {

          el.mergeAttributes(document.createElement("<INPUT name='" + newName + "'/>"), false);

          }

          };

          Demo:

          Before OUTERHTML:

          <INPUT id=renameTarget value="Set Random Name" type=submit>
          posted on 2010-06-04 06:04 seal 閱讀(307) 評論(0)  編輯  收藏 所屬分類: Javascript
          主站蜘蛛池模板: 时尚| 邹平县| 偏关县| 师宗县| 新化县| 淮阳县| 阳原县| 邻水| 丰台区| 凯里市| 阿拉善左旗| 陵水| 松江区| 突泉县| 溧水县| 扎鲁特旗| 涪陵区| 梅州市| 宣威市| 全州县| 三门峡市| 阳谷县| 和林格尔县| 绥中县| 泸水县| 方城县| 辽阳市| 德庆县| 乌审旗| 新田县| 监利县| 会宁县| 安多县| 河间市| 荣昌县| 綦江县| 出国| 肃宁县| 苏尼特右旗| 阳江市| 海晏县|