Sealyu

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

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(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 閱讀(310) 評(píng)論(0)  編輯  收藏 所屬分類: Javascript
          主站蜘蛛池模板: 新干县| 高陵县| 伊通| 中西区| 天峨县| 汤原县| 双流县| 连南| 霍林郭勒市| 赫章县| 始兴县| 运城市| 绥中县| 常熟市| 东明县| 宜阳县| 湘乡市| 江山市| 永定县| 武平县| 客服| 洛南县| 泰安市| 浑源县| 彝良县| 监利县| 石首市| 北辰区| 漳浦县| 贵南县| 仙居县| 台湾省| 永川市| 拜城县| 闽侯县| 淮北市| 新密市| 马鞍山市| 宝丰县| 安化县| 黄龙县|