2017-08-27 34 views
-1

我想建立一個網站,將從fontbit(一個希伯來語字體公司)下載字體。 這裏我所做的:HTML和JS的形式,不工作

<!DOCTYPE html> 
<html> 
<head> 
<title>הורדת פונטים מפונטביט בחינם</title> 
</head> 
<body align="center"> 
<form name="form" onsubmit="return downloadFont()" method="post"> 
<span dir="rtl" align="center">שם הפונט באנגלית:</span><br> 
<input type="text" name="name"><br><br> 
<input align="left" type="radio" name="fonttype" value="regular">Regular<br> 
<input align="left" type="radio" name="fonttype" value="bold">Bold<br><br> 
<input type="submit" value="download"> 
</form> 
<script> 
function downloadFont() { 
    var fontName = document.form["form"]["name"].value; 
    var fontType= document.form["form"]["fonttype"].value; 
    function bold() { 
    var url = "http://fontface.co.il/fonts/"+fontName+"boldwebfont.eot"; 
    window.location=url; 
    } 
    function regular() { 
    var url = "http://fontface.co.il/fonts/"+fontName+"regularwebfont.eot"; 
    window.location=url; 
    } 
    if (fontType == regular) { 
    regular(); 
    } 
    if (fontType==bold) { 
    bold(); 
    } 
    else { 
    alert("error"); 
    } 
} 

</script> 
</body> 
</html> 

林初學,所以也許我做了一個巨大的錯誤, 的問題是,當我點擊下載中心應該帶我去的URL。 但它什麼都不做。 (希伯來語文本是「英文字體mame:」)

+0

函數bold()的結果 - HTTP錯誤404.0 - 未找到 您正在查找的資源已被刪除,名稱已更改或暫時不可用。 – Wordica

+0

這是什麼意思?我是一個總的初學者 –

+0

這些是受版權保護的字體,你需要有一個許可證,標題說「從字體位下載免費字體」的事實可能是非法使用 –

回答

0

您在代碼中有幾個錯誤。只要將你的代碼與這個代碼進行比較,你就會知道你做了什麼錯誤。 試試這個代碼:

<!DOCTYPE html> 
<html> 
<head> 
<title>הורדת פונטים מפונטביט בחינם</title> 
</head> 
<body align="center"> 
<form name="form" onsubmit="return downloadFont()" method="post"> 
<span dir="rtl" align="center">שם הפונט באנגלית:</span><br> 
<input type="text" name="name"><br><br> 
<input align="left" type="radio" name="fonttype" value="regular">Regular<br> 
<input align="left" type="radio" name="fonttype" value="bold">Bold<br><br> 
<input type="submit" value="download"> 
</form> 
<script> 
function downloadFont() { 
    var fontName = document.forms["form"]["name"].value; 
    var fontType= document.forms["form"]["fonttype"].value; 

    if (fontType == 'regular') { 
    regular(fontName); 
    } 
    else if (fontType=='bold') { 
    bold(fontName); 
    } 
    else { 
    alert("error"); 
    } 
} 
function bold(fontName) { 
    var url = "http://fontface.co.il/fonts/"+fontName+"boldwebfont.eot"; 
    window.open(url, '_blank'); 
} 
function regular(fontName) { 
    var url = "http://fontface.co.il/fonts/"+fontName+"regularwebfont.eot"; 
    window.open(url, '_blank'); 
} 

</script> 
</body> 
</html> 

也許有需要在你的URL稍加修改。

+1

「只是比較你的代碼」,實際上你**應該解釋OP他的代碼有什麼問題...... – Ivan

+0

你的代碼中也有幾個錯誤,正如已經指出的那樣 - 你可以使用這裏的工具來識別它們:https://validator.w3.org/#validate-by-input 輸出爲: 第6行:在此處元素正文不允許使用屬性對齊方式。 第8行:此時不允許在元素跨度上進行屬性對齊。 第10和11行:輸入元素上的align屬性已過時。改用CSS。 除此之外還有許多其他應該考慮的問題。 – srattigan

+0

其實我只是專注於JavaScript,這就是爲什麼我忘記改變這一點。無論如何謝謝你。 –