所以我有一個作業,我們必須創建一個包含多個元素的表單。其中之一是復選框,選中后,應在新選項卡中打開結果頁面中顯示的鏈接。沒有 Javascript,只有 html 和 css!
fieldset{
display: table;
}
p{
display: table-row;
}
label{
font-family: Arial;
padding: 10px;
display: table-cell;
}
input{
margin-left: 30px;
display: table-cell;
}
<form action="https://www.google.com/search">
<fieldset>
<!--Google search/field-->
<legend>Google search</legend>
<p>
<label for="search">Search</label>
<input id="search" name="q" type="text">
</p>
<!--Google search/slider-->
<p>
<label for="hits">Number of hits</label>
<input id="hits" type="range"
min="1" max="10" value="5"
oninput="rangeValue.innerText = this.value"
name="num">
</p>
<!--Google search/Checkbox-->
<p>
<label for="newTab">New Tab</label>
<input id="newTab" type="checkbox"
name="target" value="_blank">
</p>
<!--Start search-->
<input type="submit" value="Start search">
</fieldset>
</form>
At 是我嘗試過的代碼,但我無法讓它作業。對不起,如果代碼有點亂,我們現在只有一個月的時間進入 html 而我才剛剛開始學習:)
uj5u.com熱心網友回復:
對于谷歌搜索,沒有 url 引數target=_blank
您必須設定引數newwindow=1。
帶有作業引數的部分代碼(復選框欄位):
<!--Google search/Checkbox-->
<p>
<label for="newTab">New Tab</label>
<input id="newTab" type="checkbox"
name="newwindow" value="1">
</p>
uj5u.com熱心網友回復:
如果沒有 JS,您可能無法實作這一目標
_blank如果選中輸入,則onclick 中的這個小腳本將表單目標切換到(新選項卡)或_self(相同選項卡)如果未選中。
您必須在表單中添加 id 屬性,在本例中我使用了“myForm”
<p>
<label for="newTab">New Tab</label>
<input id="newTab" type="checkbox" onclick="if(this.checked) document.getElementById('myForm').setAttribute('target', '_blank'); else document.getElementById('myForm').setAttribute('target', '_self')">
</p>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/340235.html
下一篇:內網神器cs4.0使用說明書
