原來的js中代碼為:
var theform = document.forms[0];
theform.appendChild(document.createElement("<input type='hidden' name='__EVENTTARGET'>"));
這樣在IE中好用,但是Firefox中就是不行。
把document.createElement("<input type='hidden' name='__EVENTTARGET'>")拿出來測試,發現在這行就有錯誤了。
報:String contains an invalid character" code: "5
在網上找到的說Firefox重要用 document.createElement(option);註:我需要的是input,所以:
var options = document.createElement("input");
options.setAttribute("name", "__EVENTARGUMENT");
options.setAttribute("type", "hidden");
theform.appendChild(options);
Firefox中和IE都不好用了,還是:String contains an invalid character" code: "5
參考下面調用的代碼
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
考慮是不是需要個ID:
var options = document.createElement("input");
options.setAttribute("name", "__EVENTARGUMENT");
options.setAttribute("id", "__EVENTARGUMENT");
options.setAttribute("type", "hidden");
theform.appendChild(options);
果然好用!