HTML表单按钮值不会在Safari和Chrome中发布 [英] HTML Form Button value is not posted in Safari and Chrome
问题描述
我使用jQuery在单击按钮时提交表单。然后我想测试按钮的值,但是,这不会在Safari和Chrome中提交。为什么?是否有解决方法?
在IE / FF中测试以下代码,看看它是否有效,然后在Safari / Chrome中进行测试,看看它是否:
ButtonPostTest.php:
<?php
if(isset($ _ POST ['testBtn'])){
echo $ _POST ['testBtn'];
}
?>
< html>
< head>
< title>< / title>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js>< / script>
< script type =text / javascript>
$(document).ready(function(){
$('#btn')。click(function(){
$('form')。submit(); //提交表格
});
});
< / script>
< / head>
< body>
< form action =method =post>
< button id =btnclass =page-btntype =submitname =testBtnvalue =是按钮值已发布!> POST IT!< / button>
< / form>
< / body>
< / html>
更新:
同样的事情发生在 input
:
< input id =btnclass =page-btntype =submitname =testBtnvalue =Post this>< / input>
另外,这仅仅是使用jQuery .submit()
。
< button type ='submit'id ='trash'name ='trash'value =trashclass = '红' >
I am using jQuery to submit a form when a button is clicked. I would then like to test the value of the button, however, this doesn't get submitted in Safari and Chrome. Why? Is there a work around?
Test the following code in IE/FF to see that it works, and then test it in Safari/Chrome to see that it does not:
ButtonPostTest.php:
<?php
if(isset($_POST['testBtn'])) {
echo $_POST['testBtn'];
}
?>
<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#btn').click(function() {
$('form').submit(); // submit the form
});
});
</script>
</head>
<body>
<form action="" method="post">
<button id="btn" class="page-btn" type="submit" name="testBtn" value="Yes Button value is posted!">POST IT!</button>
</form>
</body>
</html>
UPDATE:
The same thing happens with input
:
<input id="btn" class="page-btn" type="submit" name="testBtn" value="Post this"></input>
Also, this is only an issue when submitting using jQuery .submit()
- without this, it submits fine with either the button or input.
Give it a name.
<button type='submit' id='trash' name='trash' value="trash" class='red'>
这篇关于HTML表单按钮值不会在Safari和Chrome中发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!