我有一个包含textarea的表单。 在这个textarea上有一个模糊。 问题:当我点击提交按钮时,提交无效,因为有模糊...:
HTML:
(这段代码中有一点框架Django,但对于这个问题并不重要:一个textarea在{{formUpdateSpeciality | bootstrap}}中,它很好地被JS恢复了;))
if isset($_POST['txtboxname']) && isset($_POST['anothertxtboxname']))
THE JS :
<script>
function createFunc() {
var getForm = document.getElementById("theForm");
var getElem = document.getElementById("selectMultiple");
var optValue = getElem.options[getElem.selectedIndex].value;
var optName = getElem.options[getElem.selectedIndex].text;
var qtyDiv = document.getElementById("quantityDiv");
var createInput = document.createElement("input");
createInput.type = "text";
createInput.name = optValue;
qtyDiv.appendChild(createInput);
}
</script>
<html>
<form id="theForm" action="testpht.php" method="POST"
enctype="multipart/form-data">
<select id="selectMultiple" name="select_pro[]" class="formTxtInputmany"
multiple="multiple" onchange="createFunc()" >
<option>SELECT PRODUCT</option>
<?php
include 'mysql_connect.php';
$objDbClass = new DBConfig();
$conn = $objDbClass->get_db_pdo_func();
$sql = "SELECT pro_id,pro_name,quantity FROM products ORDER BY pro_name
ASC";
$query = $conn->query($sql);
$result = $query->fetchAll(PDO::FETCH_ASSOC);
$arrlength = count($result);
for ($x = 0; $x < $arrlength; $x++){
?>
<option value="<?php echo $result[$x]['pro_id']; ?>">
<?php echo $result[$x]['pro_name']; ?> <?php } ?>
</option> </select>
<div id="quantityDiv"></div>
input value="submit" type="submit" class="SubmtBtn"> </form>
</html>
方法 JS - 显示/隐藏表单:
<p>The text of speciality</p>
<form method="POST" id="modifSpec_{{skill.domain|cut:" "}}" name="formUpdateSpecialities" class="form" style="display:none;">
{% csrf_token %}
{{ formUpdateSpeciality|bootstrap }}
<input type="submit" name="submitSpeciality" class="btn btn-block btn-success" value="Confirm">
</form>
</div>
JS - 点击输入$(document).ready(function(){
$('div[name=speciality]').click(showForm);
});
时提交的表单:
function showForm(event){
var form = $(this).find('form');
$(this).find('p').hide();
form.show();
var textarea = $(form).find('textarea');
textarea.html($(this).find('p').html());
textarea.focus();
textarea.blur(hideForm);
}
function hideForm() {
// ** $(this) => textarea **
var thediv = $("#speciality_details_CARS");
var form = $(thediv).find('form');
form.hide();
$(thediv).find('p').show();
thediv.click(showForm);
}
因此blur()的格式为textarea。
为什么我无法提交表单?
当我点击提交按钮时,模糊被激活,因此表单隐藏并显示div。