0
好,所以我拋出了一個項目,並且我的JS經驗有限。我正在嘗試製作一個腳本,它能夠獲得一些單選按鈕單擊和文本輸入的結果,並將它們放在一起,以便將它們導向到一個IP上。 我的代碼有點工作哈哈,但我知道必須有更乾淨的方式。 當我不記得我如何嘗試這樣做,但它涉及document.getelementbyname(「loc).value,但它返回undefined ..現在,我試圖做同樣的事情與」港口「無線電我想做的事情正確的。對不起,如果我搞砸這個職位了。單選按鈕傳遞的值有問題
<label><input type="radio" name="loc" value="16" onclick= "clt();" />Carolinas</label><br>
<label><input type="radio" name="loc" value="17" onclick= "geo();"/>Georgia</label><br>
<label><input type="radio" name="loc" value="18" onclick= "sxw();"/>Xpress</label><br><br>
<label><input type="number" placeholder="Store Number" id="thirdOct" /> </label>
<label><input type="radio" name="cwPort" value="90"/>Port 90</label>
<label><input type="radio" name="cwPort" value="91"/>Port 91</label>
<label><input type="radio" name="cwPort" value="92"/>Port 92</label>
<br>
<input type="submit" class="fsSubmitButton" value="Connect" onclick="makeIp();" />
var ipAdd;
var sNum = "0";
var int = [":", 81 ];
// had to go this route for a value, because when I try to call by document.getElementByName("loc") in my makeIp function it returns undefined for the value of "loc"
function clt()
{sNum = "16";}
function geo()
{sNum = "17";}
function sxw()
{ sNum = "18";}
function makeIp()
{
var storeN = document.getElementById("thirdOct").value;
var octThree;
if (storeN >= 300 && storeN <= 399) {
octThree = storeN.slice(-2);
if (octThree < 10) {
octThree = storeN.slice(-1);
window.open("http://172." + sNum + "." + octThree + ".65" + int[0] ,"_blank");
console.log("http://172." + sNum + "." + octThree + ".65" + int[0]);
}
else {
window.open("http://172." + sNum + "." + octThree + ".65" + int[0] ,"_blank");
console.log("http://172." + sNum + "." + octThree + ".65" + int[0] );
}
}
else {
if (storeN >= 300) {
octThree = storeN.slice(-2);
if (octThree < 10) { octThree = storeN.slice(-1);
window.open("http://172." + sNum + "." + octThree + ".65" + int[0] + int[1],"_blank");
console.log("http://172." + sNum + "." + octThree + ".65" + int[0] + int[1],"_blank");
}
else {
window.open("http://172." + sNum + "." + octThree + ".65" + int[0] + int[1],"_blank");
console.log("http://172." + sNum + "." + octThree + ".65" + int[0] + int[1],"_blank");
}
}
else { octThree = storeN;
var ipAdd = "http://172." + sNum + "." + octThree + ".65" + int[0] + int[1] ;
console.log(ipAdd);
window.open("http://172." + sNum + "." + octThree + ".65" + int[0] + int[1],"_blank");
console.log("http://172." + sNum + "." + octThree + ".65" + int[0] + int[1],"_blank");
}
}
}
所以我發現了一個可能的解決方案使用下面的代碼來代替我曾打電話CLT,地理位置和SXW功能....
var radios = document.getElementsByName('genderS');
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
// do whatever you want with the checked radio
alert(radios[i].value);
// only one radio can be logically checked, don't check the rest
break;
}
}
您可以使用'document.querySelector(」 [name =「genderS」]:選中').value;'獲取選中的單選按鈕的值。 –