<html>
<head>
<script type="text/javascript">
function blz()
{
//alert("asdf");
//document.getElementById("link").innerHTML='https://www.facebook.com/dialog/feed?app_id=172099656214641&link='+encodeURI(document.getElementById("product").value)+'&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name='+encodeURI(document.getElementById("subject").value)+'&caption=Invitation%20to%20checkout%20product%20on%20Gogmat&description=Check%20this%20product%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById("message").value)+'&message=Check%20this%20product%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById("message").value)+'&redirect_uri='+encodeURI(document.getElementById("redirect").value);
document.getElementById("link").innerHTML=encodeURI("https://www.facebook.com/dialog/feed?app_id=172099656214641&link="+document.getElementById("product").value+"&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name="+document.getElementById("subject").value+"&caption=Invitation%20to%20checkout%20product%20on%20Gogmat&description=Check%20this%20product%20on%20social.gogmat.com%20now.%0A"+document.getElementById("message").value+"&message=Check%20this%20product%20on%20social.gogmat.com%20now.%0A"+document.getElementById("message").value+"&redirect_uri="+document.getElementById("redirect").value);
//document.getElementById('button1').href='https://www.facebook.com/dialog/feed?app_id=172099656214641&link='+encodeURI(document.getElementById("product").value)+'&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name='+encodeURI(document.getElementById("subject").value)+'&caption=Invitation%20to%20checkout%20product%20on%20Gogmat&description=Check%20this%20product%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById("message").value)+'&message=Check%20this%20product%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById("message").value)+'&redirect_uri='+encodeURI(document.getElementById("redirect").value);
}
</script>
</head>
<body>
<form action="#">
subject:<input type="text" id="subject" name="subject" value="" onkeyup="return blz()" /><br/>
personal message:<input type="text" id="message" name="message" value="" onkeyup="return blz()" /><br/>
select product for recommend:<input type="text" id="product" name="product" value="" onkeyup="return blz()" /><br/>
link return:<input type="text" id="return" name="return" value="" onkeyup="return blz()" /><br/>
<textarea id="link" name="link" rows="10" cols="40" readonly></textarea><br/>
<a id="button1" href="" target="_blank"><img src="http://social.gogmat.com/components/com_referal/assets/images/bg_send.gif" alt="send button" /></a><br/>
<input type="submit" />
</form>
</body>
</html>
这可能是什么问题,面对上面代码的问题,它没有在textarea或href部分的锚标签中显示文本,我在javascript中第一次关于这方面完全混淆。
答案 0 :(得分:0)
要设置<textarea>
的值,请更新其“值”属性:
document.getElementById("link").value = encodeURI("https://www.facebook.com/dialog/feed?app_id=172099656214641&link="+document.getElementById("product").value+"&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name="+document.getElementById("subject").value+"&caption=Invitation%20to%20checkout%20product%20on%20Gogmat&description=Check%20this%20product%20on%20social.gogmat.com%20now.%0A"+document.getElementById("message").value+"&message=Check%20this%20product%20on%20social.gogmat.com%20now.%0A"+document.getElementById("message").value+"&redirect_uri="+document.getElementById("redirect").value);
答案 1 :(得分:0)
您需要在搜索的元素加载完成后执行该函数(onload事件,或者在元素的结束标记之后放置脚本标记)。
答案 2 :(得分:0)
文档中不存在ID为“redirect”的元素。所以它导致了javascript错误。
我添加了缺少的元素,其值为“bleh”以进行演示。
<html>
<head>
<script type="text/javascript">
function blz()
{
//document.getElementById("link").innerHTML='https://www.facebook.com/dialog/feed?app_id=172099656214641&link='+encodeURI(document.getElementById("product").value)+'&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name='+encodeURI(document.getElementById("subject").value)+'&caption=Invitation%20to%20checkout%20product%20on%20Gogmat&description=Check%20this%20product%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById("message").value)+'&message=Check%20this%20product%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById("message").value)+'&redirect_uri='+encodeURI(document.getElementById("redirect").value);
var aurl = encodeURI("https://www.facebook.com/dialog/feed?app_id=172099656214641&link="+document.getElementById("product").value+"&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name="+document.getElementById("subject").value+"&caption=Invitation%20to%20checkout%20product%20on%20Gogmat&description=Check%20this%20product%20on%20social.gogmat.com%20now.%0A"+document.getElementById("message").value+"&message=Check%20this%20product%20on%20social.gogmat.com%20now.%0A"+document.getElementById("message").value+"&redirect_uri="+document.getElementById("redirect").value);
document.getElementById("link").value = aurl;
//document.getElementById('button1').href='https://www.facebook.com/dialog/feed?app_id=172099656214641&link='+encodeURI(document.getElementById("product").value)+'&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name='+encodeURI(document.getElementById("subject").value)+'&caption=Invitation%20to%20checkout%20product%20on%20Gogmat&description=Check%20this%20product%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById("message").value)+'&message=Check%20this%20product%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById("message").value)+'&redirect_uri='+encodeURI(document.getElementById("redirect").value);
}
</script>
</head>
<body>
<form action="#">
<input type="text" name="redirect" id="redirect" value="bleh" />
subject:<input type="text" id="subject" name="subject" value="" onkeyup="return blz()" /><br/>
personal message:<input type="text" id="message" name="message" value="" onkeyup="return blz()" /><br/>
select product for recommend:<input type="text" id="product" name="product" value="" onkeyup="return blz()" /><br/>
link return:<input type="text" id="return" name="return" value="" onkeyup="return blz()" /><br/>
<textarea id="link" name="link" rows="10" cols="40" readonly></textarea><br/>
<a id="button1" href="" target="_blank"><img src="http://social.gogmat.com/components/com_referal/assets/images/bg_send.gif" alt="send button" /></a><br/>
<input type="submit" />
</form>
</body>
</html>
另一种解决方案是从字符串中删除document.getElementById("redirect").value
。