[英]How to make a speicific text value respond with different text
I'm trying to get specific value back when I write "h" but it won't, and I don't know why.当我写“h”时,我试图取回特定的值,但它不会,我不知道为什么。 I have tried searching for the problem but could not find the solution, I don't know if I am just being dumb.我试过寻找问题,但找不到解决方案,我不知道我是不是愚蠢。
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>BOING</title>
<script type="text/javascript">
function res() {
var a = getElementById("a").value;
var c;
if ( a == f ) {
c = "Hello";
}
else if ( a == j) {
c = "Hi";
}
c = document.querySelector("bleh").value;
}
</script>
</head>
<body class="bd" >
<form class="form" action="index.html">
<input id="a" type="text" name="h" pattern="Write Here" />
<button id="b" type="button" name="button" onclick="res()">Ask</button>
</form>
<div class="blah" id="bleh"></div>
</body>
</html>```
if you want to change text of DIV 'bleh' to respond to user when writing predefined message like Hello or Hi如果您想在编写预定义的消息(如 Hello 或 Hi)时更改 DIV 'bleh' 的文本以响应用户
f="Hello";j="Hi";
function res() {
var a = document.getElementById("a").value;
var c="";
if ( a == f ) {
c = "Hello";
}
else if ( a == j) {
c = "Hi";
}
document.querySelector("#bleh").innerHTML=c;
}
https://jsfiddle.net/rkv88/kjuox029/11/ https://jsfiddle.net/rkv88/kjuox029/11/
modification :修改:
1 to put text into DIV element you must use .innerHTML
property 1 要将文本放入 DIV 元素,您必须使用.innerHTML
属性
2 defined j & f 2 定义 j & f
you can use document.getElemntById("bleh")
instead of document.querySelector("#bleh").innerHTML=c;
您可以使用document.getElemntById("bleh")
而不是document.querySelector("#bleh").innerHTML=c;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.