我有一个隐藏字段,其中question_id是唯一的。我试图从下一页获取jquery中的隐藏字段,以便我可以发布表单状态的消息。
然后我将该状态放在提交表单底部的HTML中。
form.php的
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery File Upload</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
function submitForm(upload_input_field){
upload_input_field.form.submit();
return true;
}
$(function () {
});
</script>
</head>
<body>
<form action="uploadFile.php" target="uploadIframe" method="post" enctype="multipart/form-data">
<input type='button' class='btn btn-default' onClick='submitForm(this)' value='Submit' />
<input name='question_id' value='123' type='hidden' />
</form>
<iframe style="border:0;" id="uploadIframe" name="uploadIframe"></iframe>
<div id="successMessage123"></div>
</body>
</html>
uploadFile.php
<?php $question_id = $_POST['question_id']; ?>
<script>
$(document).ready(function(){
$("[name=question_id]").val(var questionid);
//alert(question_id);
//$(('#successMessage_'+question_id), window.parent.document).html('<p>hidden value success</p>');
$('#successMessage_'+question_id).html('<p>hidden value success</p>');
});
</script>
答案 0 :(得分:0)
您的JavaScript(客户端)(JQuery是一个JS库)只能解析服务器(PHP)呈现/输出的内容。一个简单的解决方案就是这样的内联PHP:
<?php $question_id = $_POST['question_id']; ?>
<script>
$(document).ready(function(){
$("[name=question_id]").val(<?=$question_id?>);
$('#successMessage_'+question_id).html('<p>hidden value success</p>');
});
</script>
答案 1 :(得分:0)
我认为这段代码可以帮助你
<?php $question_id = $_POST['question_id']; ?>
<script>
$(document).ready(function(){
$("[name=question_id]").val(<?php echo $question_id ?>);
$('#successMessage_'+<?php echo $question_id ?>).html('<p>hidden value success</p>');
});
</script>`