HTML javascript从输入获取值
如何在提交时显示的确认对话框中使用表单字段的值,如下所示HTML javascript从输入获取值,javascript,html,submit,Javascript,Html,Submit,如何在提交时显示的确认对话框中使用表单字段的值,如下所示 <form action='removefinish.php' method='post' "accept-charset='UTF-8'"> Role: <br> <select name="role"> <option value="" selected="selected"></option> <option VALUE="Administrator"> Adm
<form action='removefinish.php' method='post' "accept-charset='UTF-8'">
Role: <br>
<select name="role">
<option value="" selected="selected"></option>
<option VALUE="Administrator"> Administrator</option>
<option VALUE="Employee"> Employee</option>
</select>
<br>
<label for='username'>ID: </label>
<br>
<input type='text' name='username' id='username'/>
<br>
<br><br>
<input type='submit' name='Submit' value='Submit' onclick="return confirm('Are you sure to remove ID: ')";/>
角色:
管理员
雇员
身份证件:
您可以返回confirm('您确定要删除ID:'+document.getElementById('username').value());“
但是,您可能希望从中生成一个函数,只需
返回customConfirmFunction();
以便于阅读和将来验证,以防您需要添加更多的逻辑。您可以返回confirm('您确定要删除ID:'+document.getElementById('username').value());“
但是,您可能希望从中生成一个函数,然后返回customConfirmFunction()以使其更易于阅读和将来验证,以防您需要添加更多的逻辑。如果您不想转到另一个页面,可以使用ajax,或者将表单操作设置为同一个请求php文件。如果您不想转到另一个页面,可以使用ajax,或者将表单操作设置为相同的请求php文件。您可以执行以下操作:-
<script type="text/javascript">
var valueText=document.getElementById("username");
function confirmPopUp()
{
var bul=confirm("Are you sure to remove ID"+valueText.value);
if(bul==true)
{
//statements
}
else
{
//statements
}
}
</Script>
var valueText=document.getElementById(“用户名”);
函数confirmPopUp()
{
var bul=confirm(“您确定要删除ID吗”+valueText.value);
如果(bul==true)
{
//声明
}
其他的
{
//声明
}
}
您可以执行以下操作:-
<script type="text/javascript">
var valueText=document.getElementById("username");
function confirmPopUp()
{
var bul=confirm("Are you sure to remove ID"+valueText.value);
if(bul==true)
{
//statements
}
else
{
//statements
}
}
</Script>
var valueText=document.getElementById(“用户名”);
函数confirmPopUp()
{
var bul=confirm(“您确定要删除ID吗”+valueText.value);
如果(bul==true)
{
//声明
}
其他的
{
//声明
}
}
您需要钩住表单的提交事件
在您的例子中,您需要给表单
元素一个ID,在本例中,我们给它一个IDformID
<form id="formID" action="removefinish.php" method="post" "accept-charset='UTF-8'">
您需要在加载文档后执行此操作,以确保javascript能够找到表单,而不是在表单添加到DOM之前进行查看。要做到这一点,您可以简单地使用以下内容:
function formHook() {
document.getElementById('formID').addEventListener('submit', function(e) {
// This will fire when the form submit button is pressed,
// or when the user presses enter inside of a field.
// Get the value from the username field.
var value = document.getElementByID('username').value;
// Ask the user to confirm.
if (!confirm('Are you sure you wish to remove ' + value + ' from the database?')) {
// Stop the form from processing the request.
e.preventDefault();
return false;
}
}, false);
}
window.addEventListener('load', formHook, false);
现在,当文档完成加载后,将调用
formHook
函数。您需要钩住表单的提交事件
在您的例子中,您需要给表单
元素一个ID,在本例中,我们给它一个IDformID
<form id="formID" action="removefinish.php" method="post" "accept-charset='UTF-8'">
您需要在加载文档后执行此操作,以确保javascript能够找到表单,而不是在表单添加到DOM之前进行查看。要做到这一点,您可以简单地使用以下内容:
function formHook() {
document.getElementById('formID').addEventListener('submit', function(e) {
// This will fire when the form submit button is pressed,
// or when the user presses enter inside of a field.
// Get the value from the username field.
var value = document.getElementByID('username').value;
// Ask the user to confirm.
if (!confirm('Are you sure you wish to remove ' + value + ' from the database?')) {
// Stop the form from processing the request.
e.preventDefault();
return false;
}
}, false);
}
window.addEventListener('load', formHook, false);
现在,当文档完成加载后,将调用
formHook
函数。将onclick
属性替换为以下内容:
onclick="return confirm('Are you sure to remove ID ' +
document.getElementById('username').value + '?')"
将
onclick
属性替换为以下内容:
onclick="return confirm('Are you sure to remove ID ' +
document.getElementById('username').value + '?')"
与php无关,标记已删除。与php无关,标记已删除。野生。直线格式,我以前没见过!狂野的。直线格式,我以前没见过!谢谢您,陛下。简单易懂,谢谢大家的回答。谢谢陛下。简单易懂,谢谢大家的其他回答。