1

我有一个简单的问题,

如何改变

window.alert ('Please input data into the \"Part No.\" field.');

只是文本,没有警报

Please input data into the \"Part No.\" field.
4

2 回答 2

1

这取决于您希望将文本放置在何处:

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();
于 2013-05-27T01:13:58.500 回答
1

我假设您只想将其写入您的文档?将此包含<script>在您的块中<body>

document.write('<p>Please input data into the &quot;Part No.&quot; field.</p>');

编辑:重新考虑这一点,我现在相信您希望消息出现在输入元素之后。在这里,假设您的输入元素是<input id="part_no_field" />

// Create a message node
var messageNode = document.createElement('p');
messageNode.innerText = 'Please input data into the &quot;Part No.&quot; 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);
}
于 2013-05-27T01:08:00.667 回答