我正在使用jQuery在單擊按鈕時提交表單。然後,我想測試該按鈕的值,但是,這不會在Safari和Chrome中提交。爲什麼?有沒有解決辦法?HTML表單按鈕值未在Safari和Chrome中發佈
測試在IE/FF下面的代碼,看看它的工作原理,並對其進行測試Safari /鉻中看到它沒有:
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:
同樣的事情發生與input
:
<input id="btn" class="page-btn" type="submit" name="testBtn" value="Post this"></input>
此外,這只是一個問題時,提交使用jQuery .submit()
- 沒有這個,它提交罰款與按鈕或輸入。
感謝這個我指出了正確的方向。正在讓我發瘋,甚至沒有懷疑我之前添加的jquery.submit ...我發現了這種行爲的解釋以及它爲什麼會發生:http://stackoverflow.com/a/1709352/76672 – Jake 2014-06-26 20:53:20
似乎工作在Chrome(Linux Mint)中確定。它已經使用Webkit的一段時間了,現在可能已經在Chrome中修復了。 – 2015-01-20 02:09:03