您可以使用此功能:
function changeAttributes() {
var x = document.getElementsByName("textInput");
for(var i = 0; i < x.length, i++) {
x[i].setAttribute("oninvalid", "please, only use letters");
}
}
尝试以下:
$('input[name=textInput]').attr("oninvalid", "please, only use letters");