Php 通过javascript警告文本框
非常简单的问题!我想知道如何使用javascript来提醒我文本框中的某些内容…不确定我现在所做的工作是否正常。这是函数Php 通过javascript警告文本框,php,javascript,html,Php,Javascript,Html,非常简单的问题!我想知道如何使用javascript来提醒我文本框中的某些内容…不确定我现在所做的工作是否正常。这是函数 function alertNow(comment){ alert(comment); } 现在是文本框 <input type = 'text' name = 'txt_comment'> <button onClick = alertNow(txt_comment.value) value = "Submit Comment"></butt
function alertNow(comment){
alert(comment);
}
现在是文本框
<input type = 'text' name = 'txt_comment'>
<button onClick = alertNow(txt_comment.value) value = "Submit Comment"></button>
当然这是可行的,我以前做过,但我只是忘记了一些语法问题。有什么想法吗?谢谢
<input type="text" id="testTextarea">
<input type="submit" value="Test" onClick="alert(document.getElementById('testTextarea').value);" />
您缺少报价单。也可以使用ID而不是名称
<input type = 'text' name = 'txt_comment' id='txt_comment'>
<button onClick = 'alertNow(txt_comment.value)' value = "Submit Comment"></button>
也可以更好地使用document.getElementById,如下所示
<button onClick = 'alertNow(document.getElementById("txt_comment").value)' value = "Submit Comment"></button>
函数alertNow(){
var a=document.getElementById(“txt_注释”).value;
警报(a);
}
以下是完成任务的代码
//js代码
function alertNow(){
alert(document.getElementById('txt_comment').value);
return false;
}
//html代码
<form name="form_1" id="form_1" method="post">
<input type = 'text' id='txt_comment' name = 'txt_comment'>
<input type="button" onClick = "return alertNow();" value = "Submit Comment"/>
</form>
使用ID而不是名称
<input type = 'text' name = 'txt_comment' id='txt_comment'>
<button onClick = 'alertNow(txt_comment.value)' value = "Submit Comment"></button>
函数alertText(){
警报(document.getElementById('txt_comment').value);
}
<input type = 'text' name = 'txt_comment' id="txt_comment">
<button onClick = "alertText()" value= "Submit Comment"></button>