所以我为此工作了好几个小时,但我无法找到正确的算法,当文本区域的值发生变化时如何更新函数的参数。
<script>
details = "";
postid = <? php echo $_GET['id']; ?> ;
userid = <? php echo User::GetUserID($_SESSION['username']); ?> ;
postedby = posted_by;
function offerIt() {
//created a function so that we can get the latest value of the textarea because at first it was giving the default value which was null because at the page load the value is null of the textarea
addPostOffer('' + details + ',' + postid + ',' + userid + ',' + postedby + '');
}
</script>
<textarea placeholder="Type in you offer details" rows="5" class="input-block-level" id="offer_details" onblur="details=this.value"></textarea>
<script>
document.write("<input type='submit' class='btn btn-primary pull-right' onclick='offerIt()' value='Offer It' />");
</script>
所以实际上我希望details
变量得到更新。首先我将它的值设置为 "" 然后onblur
是 textarea( #offer_details
) 的值,但现在我希望 addPostOffer 的参数也被更新,但这并没有发生!我怎样才能做到这一点?
这就是document.write
正在写的内容:
<input type="submit" class="btn btn-primary pull-right" onclick="offerIt()" value="Offer It">
请帮忙。