Javascript 清除时等于string.length 4

Javascript 清除时等于string.length 4,javascript,Javascript,我不希望用户能够发送空白文本消息。当用户清除p标记并单击send..时,它将以string.length的形式返回到4,此时它应为0。我还希望用户发送一条消息并向窗口发出警报,并将其记录在文本区域中 守则: 您的文本区域包含字符。保持它为空,就像这样: 你可以 编辑:添加结果图像您的文本区域包含字符。保持空着,就像这样:我检查过了,没问题。请把我的答案记为正确答案。谢谢这是另一个问题的答案!你还没有找到。正如您在代码中看到的,在上面的解决方案中不需要它。我知道我是正确的&我向您显示了0的值,您可

我不希望用户能够发送空白文本消息。当用户清除p标记并单击send..时,它将以string.length的形式返回到4,此时它应为0。我还希望用户发送一条消息并向窗口发出警报,并将其记录在文本区域中

守则:


您的文本区域包含字符。保持它为空,就像这样:

你可以


编辑:添加结果图像

您的文本区域包含字符。保持空着,就像这样:我检查过了,没问题。请把我的答案记为正确答案。谢谢这是另一个问题的答案!你还没有找到。正如您在代码中看到的,在上面的解决方案中不需要它。我知道我是正确的&我向您显示了0的值,您可以在该值上执行任何您想要的操作。但是说实话,你拒绝了我的回答没有什么好的理由,所以让我们不要再互相打扰了。谢谢你帮助我理解字符串。长度=4是什么。为什么这个值默认出现我不知道!我只是用string.value来找到它,而string.includes用来删除它。一个更简单的方法是遵循@Mulli的建议。在p内容可编辑标签中没有任何文本。非常感谢您帮助我理解!!这是代码的帮助下,多,我整理!
    <p id="sendMe"  onclick="myFunky()" contenteditable="true">
      Highlight all of the text you see here, including this and delete 
      it, and this, then enter a message..click send!
    </p><br>

    <button class="button" onclick="myFun()">Send</button><br>

    <textarea onclick="myFunk()" id="message" rows="4" cols="50" readonly>           
   </textarea>

    <script>

      function myFunk() {

        document.getElementById("message").innerHTML = "Please delete the 
        above    line 'Highlight all of the text you see here, including 
        this and delete it, and this, then enter a message..click send!'. 
        Thank you!"
      }

      function myFunky() {

        document.getElementById("sendMe").style.color = "black";
        document.getElementById("message").innerHTML= "That's It!";
      }

      function myFun() {
        document.getElementById("sendMe").style.color = "blue";
        document.getElementById("message").style.color = "red";

        var str = document.getElementById("sendMe").innerHTML;
        var x = str.valueOf();
        var y = str.length;
        var n = str.includes("Highlight all of the text you see here, including  this and delete it, and this, then enter a message..click send!");


        if (n == true) {

          document.getElementById("message").innerHTML ="Delete the above line &    write a text!";
        } else if (x == 0) {
          alert ("That was Blank!");
          document.getElementById("message").innerHTML ="Don't be shy! Come on  write some text!!";
        } else {

          document.getElementById("message").innerHTML = "Your text:  " 
          +str+ "    was recorded momentarily";
          document.getElementById("message").style.color = "green";
          document.getElementById("sendMe").innerHTML = ""
          alert ("Thank you for your time and text: " +str + "  the
          string.length of your text = " + y + " characters in length.");
        }
      };

    </script>
<body style="background-color:yellow;">

<p id="sendMe" onclick="myFunky()" contenteditable="true">Highlight all of the   text you see here, including this and delete it, and this, then enter a message..click send!</p><br>

<button class="button" onclick="myFun()">Send</button><br>

<textarea onclick="myFunk()" id="message" rows="4" cols="50" readonly> </textarea>




function myFunk() {

document.getElementById("message").innerHTML = "Please delete the above line    'Highlight all of the text you see here, including this and delete it, and this, then enter a message..click send!'. Thank you!"
}
function myFunky() {

document.getElementById("sendMe").style.color = "black";
document.getElementById("message").innerHTML= "That's It send me a text!";
}

function myFun() {
document.getElementById("sendMe").style.color = "blue";
document.getElementById("message").style.color = "red";

var str = document.getElementById("sendMe").innerHTML;
var x = str.valueOf();
var y = str.length;
var v = str.includes("<br>");
var n = str.includes("Highlight all of the text you see here, including this  and delete it, and this, then enter a message..click send!");


if (v==true || y==0) {
document.getElementById("message").innerHTML ="Write a text!!";
alert ("Don't be cheeky ! That was a blank text!");

} else if (n==false){

document.getElementById("message").innerHTML = "Your text:  " +str+ " was   recorded momentarily";
document.getElementById("message").style.color = "green";
document.getElementById("sendMe").innerHTML = ""
alert ("Thank you for your time and text: " +x);
}

else {


alert ("You haven't sent a message");
document.getElementById("message").innerHTML ="Don't be shy! Come on write some    text!!";

}
};
<body id="Bground" onclick="myFunky()" style="background-color:#ff3110;">
<h4> Please send me a message!</h4> <h5>Text me on the dotted line:</h5>

<p id="sendMe"  onclick="myFunky()" contenteditable="true" style="border- bottom:dotted; width:500px"></p><br>

<button class="button" onclick="myFun()">Send</button><br>

<textarea id="message" rows="4" cols="50" readonly></textarea>

function myFunky() {
document.getElementById("Bground").style.backgroundColor = "white";
document.getElementById("sendMe").style.backgroundColor = "red";
document.getElementById("sendMe").style.color = "white";
document.getElementById("message").innerHTML= "That's It!";
}

function myFun() {
document.getElementById("sendMe").style.color = "blue";
document.getElementById("message").style.color = "red";

var str = document.getElementById("sendMe").innerHTML;
var x = str.valueOf();
var y = str.length;
//var n = str.includes("Highlight all of the text you see here, including  this  and delete it, and this, then enter a message..click send!");


if (y == 0){
document.getElementById("message").innerHTML ="You have not entered any text!";
alert ("Please enter some text to send! Make it snappy!")
} else if (x==0){

alert ("That was Blank!"+str.length);
document.getElementById("message").innerHTML ="Don't be shy! Come on  write some text!!";
}

else {

document.getElementById("message").innerHTML = "Your text:>  " +str+ " <:was  recorded momentarily";
document.getElementById("message").style.color = "green";
document.getElementById("sendMe").innerHTML = ""
alert ("Thank you for your time! Your Text:> " +str+ " <:has been received!");

}
};