English 中文(简体)
61 JS: showing html w/ factors through document. 书写
原标题:JS: Displaying html w/ variables via document.write
  • 时间:2009-09-01 19:06:23
  •  标签:

我刚刚开始学习联合材料,并且(当然)有一些困难。 我通常会很快地抓住事情,但我可以 life忙找到解决办法。 下面请见understand,原因何在。

我的目标是使用3个迅速的箱子,所有箱子都相互交织,以印刷一部《html》的法典,这将是一部简单的《URL》。 我对此再说一遍,但我要首先谈谈。

目前,我正在迅速采取行动,但在我把数据输入第三箱并提交之后,没有发生。

我在这里做了什么错误? 如果与我的文件发生错误。 书写法,我应当研究什么?

感谢!

function show_prompt()
{
    var site_type = prompt("What kind of link is this?");
    var site_url = prompt("What is the URL?");
    var site_title = prompt("Give the link a title");
    if (site_type = website) {
        document.write("<a style="color: #777777" href="http://site_url" title="site_title">site_title</a>");
    }
    else 
        if (site_type = video) {
            document.write("<a style="color:#98B2C3" href="http://site_url" title="site_title">site_title</a>");
        }
        else 
            if (site_type = image) {
                document.write("<a style="color:#8D5359" href="http://site_url" title="site_title">site_title</a>");
            }
            else 
                (site_type = article); {
                 document.write("<a style="color:#768D53" href="http://site_url" title="site_title">site_title</a>");
                }
}
最佳回答

甚至在我们开始努力通过发言将如何奏效之前,我们需要在你的发言中确定以下事实:你是在<>上签字的<>而不是comparing

如果你需要2个相同迹象的话,就不必在你的发言中签字。 与此类似:

if (site_type == website)

采用单一 = 标志来分配变量,因此,如果你将网站的价值实际分配给网站类型——而不是比较两个适当数值。

为此:

function show_prompt()
{
        var site_type = prompt("What kind of link is this?");
        var site_url = prompt("What is the URL?");
        var site_title = prompt("Give the link a title");
        if (site_type == "website") {
            document.write("<a style="color: #777777" href="http://"+site_url+"" title="site_title">"+site_title+"</a>");
        }
        if (site_type == "video") {
            document.write("<a style="color:#98B2C3" href="http://"+site_url+"" title="site_title">"+site_title+"</a>");
        }
        if (site_type == "image") {
            document.write("<a style="color:#8D5359" href="http://"+site_url+"" title="site_title">"+site_title+"</a>");
        }
        if(site_type == "article") {
            document.write("<a style="color:#768D53" href="http://"+site_url+"" title="site_title">"+site_title+"</a>");
        }
}

I ve made a few changes to your code in the above chunk, not just removing the else statements. I ve also made the if() comparisons check against strings rather than against empty variables as you had before and I ve changed the document.write functions to use the added prompt strings in them. If we can get that to work, we can start thinking about where we really want to put the else statements at a later date :)

问题回答

replace "if (site_type = website) {" for "if (site_type == website) {" and others.

除了从Sterpike和Andres进行的转让与比较问题外,由于您将<代码>>>> 类型与另一个变量:websitevideo_image>>>>>article相比较,您将遇到问题。 这些是未实现的变量,因此,条件是实际检查<代码>site_type = 无

您的原始法典中所发生的情况如下:

// The value on the right side of the = is assigned to site_type.
// All of these are uninitialized, so will evaluate to null
// Since null is falsy, each conditional fails
if (site_type = website){ 
...
} else if (site_type = video){
...
} else if (site_type = image){
...
} else if (site_type = article){
...
}

除了使用转让而不是比较操作者外,你或许还应引用你的指示。

指称:

if (site_type ==  video ) {
                        document.write("<a style="color:#98B2C3" href="http://site_url" title="site_title">site_title</a>");
                }

除非这些实际上意在变数,否则,<代码>video<>/code>,如无界定,将产生错误,从而造成 your本末。

If you re not using Firefox, download it and install Firebug. http://getfirebug.com/

这将使你知道 Java的错误是什么,并提供许多其他工具。





相关问题
热门标签