所以我正在研究这个问题好几个小时,而且我无法找到正确的算法,当textarea的值发生变化时,如何更新函数的参数。
<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
变量得到更新。首先,我将其值设置为&#34;&#34;然后是onblur
textarea(#offer_details
)的值,但是之后我想要更新addPostOffer的参数,但是没有发生!我怎么能这样做?
这就是document.write
写的内容:
<input type="submit" class="btn btn-primary pull-right" onclick="offerIt()" value="Offer It">
请帮忙。
答案 0 :(得分:0)
我测试了你的代码,问题出在这里:
postid = <? php echo $_GET['id']; ?> ;
userid = <? php echo User::GetUserID($_SESSION['username']); ?> ;
应改为:
postid = "<?php echo $_GET['id']; ?>";
userid = "<?php echo User::GetUserID($_SESSION['username']); ?>";
现在整个代码变成了,我添加了Posted_by = userid;定义它:
<script>
details = "";
postid = "<?php echo $_GET['id']; ?>";
userid = "<?php echo User::GetUserID($_SESSION['username']); ?>";
posted_by = userid;
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>