2017-02-21 69 views
0

因此,我目前正在爲我校網絡管理培訓做最後一次實習。我被要求創建一個簡單的網頁,允許選擇一系列服務器來執行乾淨的安裝。喜歡:當我選擇'服務器1'和'服務器4'>點擊'提交'>確認我的動作>啓動執行乾淨安裝的VBscript。確認操作後啓動腳本(HTML)

我迄今(也指其結束代碼段): - 基本歡迎文本 - 複選框 - 全選(JavaScript)的 - Continue按鈕 - 當點擊繼續按鈕>顯示警告要求確認

我想要做的是確認後啓動所選框的腳本。那可能嗎?我的意思是,我認爲我需要別的東西而不是HTML。 Javascript可能?我會怎麼做這樣的事情?

我不是這方面的專家,根本不是。我確實有一些HTML和CSS的經驗,但Javascript和所有這一切?不,不是。很高興能有一些幫助!

<html> 
<head> 
<title> 
Huawei Cleaning Center 
</title> 
<script type="text/javascript"> 
function SetAllCheckBoxes(FormName, FieldName, CheckValue) 
{ 
    if(!document.forms[FormName]) 
     return; 
    var objCheckBoxes = document.forms[FormName].elements[FieldName]; 
    if(!objCheckBoxes) 
     return; 
    var countCheckBoxes = objCheckBoxes.length; 
    if(!countCheckBoxes) 
     objCheckBoxes.checked = CheckValue; 
    else 
     // set the check value for all check boxes 
     for(var i = 0; i < countCheckBoxes; i++) 
      objCheckBoxes[i].checked = CheckValue; 
} 
</script> 
<script type="text/javascript"> 
function clicked() { 
     if (confirm('Weet u zeker dat u wilt doorgaan?')) { 
      yourformelement.submit(); 
     } else { 
      return false; 
     } 
    } 

</script> 
</head> 
<body> 
<center><h1>Welkom bij Huawei Cleaning Center!</h1></center> 
<br><br> 
Kruis één of meerdere van de volgende servers aan waarop u een Clean Install wilt uitvoeren:<br><br> 
<form method="GET" action="page17.php" name="myForm" onsubmit="return false;"> 
<label for="myCheckbox1"> 
<input type="checkbox" name="myCheckbox" value="1" id="myCheckbox1"> 
172.16.115.11 </label> 
<br> 
<label for="myCheckbox2"><input type="checkbox" name="myCheckbox" value="2" id="myCheckbox2"> 
172.16.115.21 </label> 
<br> 
<label for="myCheckbox3"><input type="checkbox" name="myCheckbox" value="3" id="myCheckbox3"> 
172.16.115.31 </label> 
<br> 
<label for="myCheckbox4"><input type="checkbox" name="myCheckbox" value="4" id="myCheckbox4"> 
172.16.115.41 </label> 
<br><br><input type="submit" id="submit1" onclick="clicked();" value="Doorgaan"> 
<input type="button" onclick="SetAllCheckBoxes('myForm', 'myCheckbox', true);" value="Selecteer alles"> 
<input type="button" onclick="SetAllCheckBoxes('myForm', 'myCheckbox', false);" value="Deselecteer alles"> 
</form> 
</body> 
</html> 
+2

請包括到目前爲止你寫的代碼。您提供的細節越多,您可能收到的答案就越多。檢查[FAQ](http://stackoverflow.com/tour)和[如何提問](http://stackoverflow.com/help/how-to-ask)。 –

+0

確認()後,您可以重定向到特定的VBscript啓動頁面:window.location.replace(「your-page」); – Ruby

回答

0

改變你的js這樣。如果單擊Yes

<script type="text/javascript"> 
    function clicked() { 
    var confirmed = confirm('Weet u zeker dat u wilt doorgaan?') 
    if (confirmed) { 
     yourformelement.submit(); 
    } else { 
     alert('You clicked No'); 
    } 
} 

</script> 
0

形式會提交如果你使用JQuery,你也可以這樣做:

$(yourformelement).submit(function(e){ 
    var dialogresult = confirm('Confirm'); 
    if (dialogresult) { 
     return true; 
    } else { 
     return false; 
    } 
}); 
1

你的代碼來看,好像你正在使用PHP。在這種情況下,你可以嘗試這樣的事情在你的PHP頁面(page17.php作爲action屬性簡稱):

if(!empty($_POST['serverList'])) { 
    foreach($_POST['serverList'] as $arg) { 
    exec('cscript "path/to/script.vbs" ' . $arg); 
    } 
} 

$_POST['serverList']包含複選框值的陣列和foraech循環將執行一個VBScript傳遞值參數。

這裏的JS/CSS/HTML代碼的片段:

function setCheckboxes(checkboxName, value) { 
 
    checkboxes = document.getElementsByName(checkboxName); 
 
    for (var i = 0, n = checkboxes.length; i < n; i++) { 
 
    checkboxes[i].checked = value; 
 
    } 
 
} 
 

 
function submitForm(checkboxName) { 
 
    checkboxes = document.getElementsByName(checkboxName); 
 
    for (var i = 0, n = checkboxes.length; i < n; i++) { 
 
    if (checkboxes[i].checked == true) { 
 
     confirmation = confirm('Weet u zeker dat u wilt doorgaan?'); 
 
     if (confirmation) { 
 
     return true; 
 
     } else { 
 
     return false; 
 
     } 
 
    } 
 
    } 
 
    alert('No server selected!'); 
 
    return false; 
 
}
.main-heading { 
 
    margin-bottom: 60px; 
 
    text-align: center; 
 
} 
 

 
.info { 
 
    margin-bottom: 60px; 
 
}
<h1 class="main-heading">Welkom bij Huawei Cleaning Center!</h1> 
 
<p class="info"> 
 
    Kruis één of meerdere van de volgende servers aan waarop u een Clean Install wilt uitvoeren: 
 
</p> 
 
<form method="POST" action="page17.php" name="myForm" onsubmit="return false;"> 
 
    <label for="checkbox-1"> 
 
    <input type="checkbox" name="serverList[]" value="1" id="checkbox-1"> 
 
    172.16.115.11 
 
    </label> 
 
    <br> 
 
    <label for="checkbox-2"> 
 
    <input type="checkbox" name="serverList[]" value="2" id="checkbox-2"> 
 
    172.16.115.21 
 
    </label> 
 
    <br> 
 
    <label for="checkbox-3"> 
 
    <input type="checkbox" name="serverList[]" value="3" id="checkbox-3"> 
 
    172.16.115.31 
 
    </label> 
 
    <br> 
 
    <label for="checkbox-4"> 
 
    <input type="checkbox" name="serverList[]" value="4" id="checkbox-4"> 
 
    172.16.115.41 
 
    </label> 
 
    <br><br> 
 
    <input type="submit" onclick="submitForm('serverList[]');" value="Doorgaan"> 
 
    <input type="button" onclick="setCheckboxes('serverList[]', true);" value="Selecteer alles"> 
 
    <input type="reset" value="Deselecteer alles"> 
 
</form>

希望它能幫助:)