javascript的小问题 函数blz() { //警报(“asdf”); //document.getElementById(“link”).innerHTML=https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+encodeURI(document.getElementById(“产品”).value)+”和picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=”+encodeURI(document.getElementById(“主题”).value)+“&caption=邀请%20在%20Gogmat上签出%20product%20%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+'&message=检查%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+重定向”+encodeURI=”(document.getElementById(“重定向”).value); document.getElementById(“link”).innerHTML=encodeURI(“https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+document.getElementById(“产品”).value+”&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=“+document.getElementById(“主题”).value”+“&caption=邀请%20在%20Gogmat上签出%20product%20on%20Gogmat&description=检查%20this%20product%20on%20social.gogmat.com%20now.%0A”+document.getElementById(“message”).value+“&message=检查%20this%20product%20on%20on%20social.gogmat.com%20now.%.%+document.getElementById(“message”).value+”&redirect_uri=“+document.getElementById(“重定向”).value”); //document.getElementById('button1')。href='0https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+encodeURI(document.getElementById(“产品”).value)+”和picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=”+encodeURI(document.getElementById(“主题”).value)+“&caption=邀请%20在%20Gogmat上签出%20product%20%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+'&message=检查%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+重定向”+encodeURI=”(document.getElementById(“重定向”).value); } 主题: 个人信息: 选择要推荐的产品: 链接返回:

javascript的小问题 函数blz() { //警报(“asdf”); //document.getElementById(“link”).innerHTML=https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+encodeURI(document.getElementById(“产品”).value)+”和picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=”+encodeURI(document.getElementById(“主题”).value)+“&caption=邀请%20在%20Gogmat上签出%20product%20%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+'&message=检查%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+重定向”+encodeURI=”(document.getElementById(“重定向”).value); document.getElementById(“link”).innerHTML=encodeURI(“https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+document.getElementById(“产品”).value+”&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=“+document.getElementById(“主题”).value”+“&caption=邀请%20在%20Gogmat上签出%20product%20on%20Gogmat&description=检查%20this%20product%20on%20social.gogmat.com%20now.%0A”+document.getElementById(“message”).value+“&message=检查%20this%20product%20on%20on%20social.gogmat.com%20now.%.%+document.getElementById(“message”).value+”&redirect_uri=“+document.getElementById(“重定向”).value”); //document.getElementById('button1')。href='0https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+encodeURI(document.getElementById(“产品”).value)+”和picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=”+encodeURI(document.getElementById(“主题”).value)+“&caption=邀请%20在%20Gogmat上签出%20product%20%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+'&message=检查%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+重定向”+encodeURI=”(document.getElementById(“重定向”).value); } 主题: 个人信息: 选择要推荐的产品: 链接返回:,javascript,function,Javascript,Function,这可能有什么问题,我正面临上述代码的问题,它没有在textarea或锚定标记的href部分显示文本,我第一次在javascript中对此感到完全困惑。要设置的值,请更新其“value”属性: <html> <head> <script type="text/javascript"> function blz() { //alert("asdf"); //document.getElementById("link").innerHTML='https://www

这可能有什么问题,我正面临上述代码的问题,它没有在textarea或锚定标记的href部分显示文本,我第一次在javascript中对此感到完全困惑。

要设置
的值,请更新其“value”属性:

<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>

您需要在正在搜索的元素完成加载(onload事件,或将脚本标记放在元素的结束标记之后)后执行该函数。

文档中不存在id为“redirect”的元素。因此,这会导致javascript错误

我添加了一个缺少的元素,其值为“bleh”,以进行演示

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);

函数blz()
{
//document.getElementById(“link”).innerHTML=https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+encodeURI(document.getElementById(“产品”).value)+”和picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=”+encodeURI(document.getElementById(“主题”).value)+“&caption=邀请%20在%20Gogmat上签出%20product%20%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+'&message=检查%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+重定向”+encodeURI=”(document.getElementById(“重定向”).value);
var aurl=encodeURI(“https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+document.getElementById(“产品”).value+”&picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=“+document.getElementById(“主题”).value+”&标题=邀请%20在%20Gogmat上签出%20product%20on%20Gogmat&描述=检查%20此%20product%20on%20social.gogmat.com%20now.%0A“+document.getElementById”(“message”).value+”&消息=检查%20此%20product%20on%20on%20social.gogmat.com%20now.%.%“+document.getElementById”(“message”).value+”&重定向_uri=“+document.getElementById”(“重定向”).value”);
document.getElementById(“link”).value=aurl;
//document.getElementById('button1')。href='0https://www.facebook.com/dialog/feed?app_id=172099656214641&link=“+encodeURI(document.getElementById(“产品”).value)+”和picture=http%3A%2F%2Fsocial.gogmat.com%2Fimages%2Flogo_03.jpg&name=”+encodeURI(document.getElementById(“主题”).value)+“&caption=邀请%20在%20Gogmat上签出%20product%20%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+'&message=检查%20on%20social.gogmat.com%20now.%0A'+encodeURI(document.getElementById(“message”).value)+重定向”+encodeURI=”(document.getElementById(“重定向”).value);
}
主题:
个人信息:
选择要推荐的产品:
链接返回:



另一个解决方案是从字符串中删除
document.getElementById(“redirect”).value

您的想法仍然不成功。但是感谢您的回复。好的,它肯定有效,但是您还必须按照@silverstrike所说的去做,并将
块移到
的末尾,或者在onload“handler。我也尝试过你的想法,但没有得到luckHe确实有一个id为“link”的
,但它在
块之后的
中。
<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>