我是想實現我的Django管理一個javascript代碼,我有兩個字段hard_drives(id爲:id_hard_drives
)和no_of_drives(id爲:id_no_of_drives
)。所以,我想no_of_drives出現只有hard_drives具有特殊的價值,像例如:意外標記<在JS
<script type="text/javascript">
$("#id_hard_drives").change(function() {
if($("#id_hard_drives").val()=="125"){
document.getElementById("#id_no_of_drives").type=text
} else {
document.getElementById("#id_no_of_drives").type=hidden
}
});
</script>
但是,我得到一個錯誤:
Unexpected token <
更新:
根據GSWV,我已更新的代碼,但它仍然用來顯示相同的錯誤,所以我刪除<script>
標籤。新的代碼看起來是這樣的:
(function($) {
$(document).ready(function() {
var hardDriveSelector = $("#id_hard_drives");
hardDriveSelector.on("change", function(){
if (hardDriveSelector.val() == "H") {
document.getElementById("id_no_of_drives").type = text;
} else {
document.getElementById("id_no_of_drives").type = hidden;
}
});
});
})(django.jQuery);
但代碼不被飛實施,腳本這麼想的做任何事情,我需要使用鑰匙向上或某事上id_hard_drives
?
使用語法hilighting和Linter獲取編輯器。請參閱:http://stackoverflow.com/questions/6803305/should-i-use-jslint-or-jshint-javascript-validation $(「。#id_hard_drives」)。change(function(){ \t if($ ( 「#id_hard_drives」)VAL()== 125){ \t \t的document.getElementById( 「id_no_of_drives」)類型=文本; \t}。 \t否則{ \t \t文檔。getElementById(「id_no_of_drives」)。type = hidden; \t} }); – digitaldonkey
歡迎來到Stack Overflow!我編輯了你的問題,刪除了謝謝和其他句子,因爲沒有必要。 – jezrael