Sealyu

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

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評(píng)論 :: 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) 評(píng)論(0)  編輯  收藏 所屬分類: Javascript
          主站蜘蛛池模板: 株洲县| 甘孜| 英吉沙县| 乌兰县| 武定县| 莱西市| 汕头市| 莎车县| 北安市| 德州市| 张家界市| 鄂尔多斯市| 彰化市| 邢台市| 志丹县| 巫溪县| 连城县| 富裕县| 芮城县| 琼结县| 石屏县| 鄄城县| 奈曼旗| 巧家县| 卢湾区| 疏附县| 巨野县| 尼勒克县| 湖南省| 涿州市| 蓝山县| 淳化县| 宣城市| 嵩明县| 大埔区| 阿拉善左旗| 巩义市| 津市市| 衡阳市| 南丹县| 广州市|