我有一个简单的问题,
如何更改
window.alert ('Please input data into the \"Part No.\" field.');
只是文字,没有警报
Please input data into the \"Part No.\" field.
答案 0 :(得分:1)
我假设您只想将其写入您的文档?将其包含在<script>
<body>
块中
document.write('<p>Please input data into the "Part No." field.</p>');
编辑:重新考虑这一点,我现在相信你希望消息出现在输入元素之后。在这里,假设您的输入元素是<input id="part_no_field" />
// Create a message node
var messageNode = document.createElement('p');
messageNode.innerText = 'Please input data into the "Part No." field.';
// Find your "part number" field
var partField = document.getElementById('part_no_field');
// Append the message node after your "part number" field
if (partField.nextSibling) {
partField.parentNode.insertBefore(messageNode, partField.nextSibling);
} else {
partField.parentNode.appendChild(messageNode);
}
答案 1 :(得分:0)
这取决于您希望放置文本的位置:
var text = 'Please input data into the \'Part No.\' field.'
//inside a div
div.innerHTML = text;
//the bottom of the body
document.body.innerHTML+=text;
//an input field
input.value = text;
//rewriting the document
document.open();
document.write(text);
document.close();