我的應用程序是使用React創建的。通過使用dispatchEvent我試圖預填充使用JS的表單字段值。它在所有瀏覽器中工作正常,但不在IE 11中。使用dispachEvent預填表單域在IE中不起作用,在所有瀏覽器中工作正常
IE控制檯顯示對象不支持錯誤。
我用來預先填寫表單域的代碼。
$(document.body).on('change', '#retailer', function() {
var retail_val = $(this).val();
//Storing the retailer value in the respective hidden text field.
if (retail_val != "0") {
var el = document.getElementById("text_6551650686371-InputField");
el.value = retail_val;
//calling the function
doEvent(el, 'input');
}
if (retail_val == "0") {
var el = document.getElementById("text_6551650686371-InputField");
el.value = "";
//calling the function
doEvent(el, 'input');
}
});
function doEvent(obj, event) {
event = new Event(event, {
target: obj,
bubbles: true
});
return obj ? obj.dispatchEvent(event) : false;
}
This is the error screenshot in IE 11 注:我試着用.VAL()方法,因爲我的應用程序是使用反應它是不工作創建。請幫助我在IE中預填表格字段值。此外,當我更改選項卡時,該字段中的值會熄滅。
爲什麼不使用'jQuery.Event'和'.trigger()'? – Barmar
我需要放置的位置以及觸發位置?請給我一個代碼片段。 –