Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.alert更改为文本_Javascript_Html - Fatal编程技术网

Javascript window.alert更改为文本

Javascript window.alert更改为文本,javascript,html,Javascript,Html,我有一个简单的问题 如何改变 window.alert ('Please input data into the \"Part No.\" field.'); 只是文字,没有提示 Please input data into the \"Part No.\" field. 我想你只是想把它写进你的文档?在您的 这取决于您希望文本放置的位置: var text = 'Please input data into the \'Part No.\' field.' //inside a div

我有一个简单的问题

如何改变

window.alert ('Please input data into the \"Part No.\" field.');
只是文字,没有提示

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

我想你只是想把它写进你的文档?在您的


这取决于您希望文本放置的位置:

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();

我不知道你的意思。你仅仅是文字是什么意思,你希望它出现在哪里?您的意思是将其转换为变量吗?可能是window.html()?将其插入页面?您不需要\“。使用
singlequote
引用字符串时,
doublequote
可以用作字符串的一部分。你也可以这样做,反之亦然。您不能使用相同的引号来引用字符串,并将其用作字符串的一部分。一旦调用该引号,就不会有“part No.”字段。无需在单引号内转义双引号。应该使用“though”的意思是
文档。write
重写整个页面,因此
零件号
不会出现在正文脚本中,例如
文档。write(“”)
不会重写整个页面。编辑为在输入字段后附加节点。
// 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);
}
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();