使用 Inserted JavaScript 访问文本框值
Accessing Textbox Value Using Inserted JavaScript
我有点问题。我正在使用 JavaScript 将 HTML 与 onblur 事件的事件处理程序一起插入网页。它看起来像这样:
return '<input id = "txtIn" type="text" value=" ' + dateTime + '" onblur= "submitManualDate(document.getElementById("txIn").value(), 2, 3);" />';
我遇到语法错误。但是,以下工作非常正常:
return '<input id = "txtIn" type="text" value=" ' + dateTime + '" onblur= "submitManualDate(1, 2, 3);" />';
知道我错过了什么吗?
在 "
(双引号)表达式中使用 "
会破坏 string
.
It's better to pass this
as an argument as you should not have multiple elements with same id
attributes in a document.
试试这个例子:
(function() {
var input = '<input type="text" value="5" onblur= "submitManualDate(this, 2, 3);" />';
document.getElementById('parent').innerHTML = input;
})();
function submitManualDate(elem, j, k) {
alert(elem.value + ' ' + j + ' ' + k);
}
<div id='parent'></div>
我有点问题。我正在使用 JavaScript 将 HTML 与 onblur 事件的事件处理程序一起插入网页。它看起来像这样:
return '<input id = "txtIn" type="text" value=" ' + dateTime + '" onblur= "submitManualDate(document.getElementById("txIn").value(), 2, 3);" />';
我遇到语法错误。但是,以下工作非常正常:
return '<input id = "txtIn" type="text" value=" ' + dateTime + '" onblur= "submitManualDate(1, 2, 3);" />';
知道我错过了什么吗?
在 "
(双引号)表达式中使用 "
会破坏 string
.
It's better to pass
this
as an argument as you should not have multiple elements with sameid
attributes in a document.
试试这个例子:
(function() {
var input = '<input type="text" value="5" onblur= "submitManualDate(this, 2, 3);" />';
document.getElementById('parent').innerHTML = input;
})();
function submitManualDate(elem, j, k) {
alert(elem.value + ' ' + j + ' ' + k);
}
<div id='parent'></div>